Convert and Cast for Date and Money format.
SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '')
The below script removes the TAB(Horozontal Tab), Line feed(New line), Carriage Return Characters in a variable @String
SET NOCOUNT ON
DECLARE @String VARCHAR(100)
DECLARE @CorrectedString VARCHAR(100)
SELECT @String = 'AB C D'
PRINT @String
SELECT @CorrectedString = REPLACE(@String, CHAR(9),'')
PRINT @CorrectedString
SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(10),'')
PRINT @CorrectedString
SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(13),'')
PRINT @CorrectedString
Extended script which also provides length of the string:
SET NOCOUNT ON
DECLARE @String VARCHAR(100)
DECLARE @CorrectedString VARCHAR(100)
SELECT @String = 'AB C D'
PRINT @String
PRINT 'LENGTH='+CAST(LEN(@String) AS VARCHAR(5))
SELECT @CorrectedString = REPLACE(@String, CHAR(9),'')
PRINT @CorrectedString PRINT 'LENGTH='+CAST(LEN(@CorrectedString) AS VARCHAR(5))
SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(10),'')
PRINT @CorrectedString PRINT 'LENGTH='+CAST(LEN(@CorrectedString) AS VARCHAR(5))
SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(13),'')
PRINT @CorrectedString PRINT 'LENGTH='+CAST(LEN(@CorrectedString) AS VARCHAR(5))
I work with a lot of databases (specifically, T-SQL databases) which collect form submissions in which there is a pretty large comment field.
Being that this is a textarea, often people make liberal use of line breaks. Unfortunately, this wreaks havoc when you try to either copy the
results from the query into Excel, or export to a CSV and then import to Excel. Even when you force double quotes around each column,
Excel still happily creates a new row whenever it sees a line break.The solution I found was to modify the SELECT query to
remove the two character entities representing line breaks and new lines in T-SQL,
which are CHAR(13) and CHAR(10). This should cover your bases for the new line characters CR, LF, and CR+LF.
The specific SQL looks like this:
SELECT REPLACE(REPLACE(@str, CHAR(13), ' '), CHAR(10), ' ')
select CONVERT(VARCHAR(10) ,getdate(),103) result
union
select CONVERT(VARCHAR(20) ,cast(555666.1258 as money),1);
result
18/10/2014
555,666.13
select isnull(null,'')
select replace(cast(666555.234666 as money),'.',',') --666555,23
select replace(cast(666555.235666 as money),'.',',') --666555,24
http://msdn.microsoft.com/en-us/library/ms187928(v=sql.105).aspx
http://msdn.microsoft.com/en-us/library/hh213505.aspx
Convert and Cast for Date and Money format.的更多相关文章
- SQL Server 2008 Datetime Cast 成 Date 类型可以使用索引(转载)
很久没写blog,不是懒,实在是最近我这的访问速度不好,用firefox经常上传不了图片 ....... 今天无意发现了SQL Server 2008 Datetime Cast 成 Date 类型可 ...
- mysql类型转换函数convert与cast的用法
原文地址:https://blog.csdn.net/kouwoo/article/details/45535733 简单介绍下mysql数据库中用于类型转换的二个函数,convert与cast函数, ...
- Convert a byte[] array to readable string format. This makes the "hex" readable!
/* * Java Bittorrent API as its name indicates is a JAVA API that implements the Bittorrent Protocol ...
- date命令转换日期命令提示date: illegal time format
问题:运行date命令抛错 date -j -f "%a %b %d %T %Z %Y" "Sat Sep 29 11:33:00 CST 2018" &quo ...
- sql 中convert和cast区别
SQL中的cast和convert的用法和区别 更多 来源:SQL学习浏览量: 学习标签: cast convert sql 本文导读:SQL中的cast 和convert都是用来将一种数据类型的表达 ...
- mysql类型转换函数convert与cast的用法,及SQL server的区别
首先,convert函数 字符集转换 : CONVERT(xxx USING gb2312) 类型转换和SQL Server一样,不过类型参数上有不同: CAST(xxx AS 类型) ...
- 使用date类和format类对系统当前时间进行格式化显示
一:Date------------String 代码1:(代码二对显示出来的时间格式进行优化) package DateDemo; import java.text.SimpleDateFormat ...
- date命令的FORMAT中输入空格的几种方法
1.date +%Y-%m-%d\ (一个空格)%H:%M:%S 此命令中用了转义字符 \ ,将空格转义出来 2.date +%Y-%m-%d' '%H:%M:%S 此命令中的单引号内可以是一个或多 ...
- "Date has wrong format. Use one of these formats instead: %, Y, -, %, m, -, %, d." DateField使用input_formats参数
错误写法 : publish_date = serializers.DateField(format="%Y-%m-%d", input_formats="%Y-%m-% ...
随机推荐
- unity update 和fixedudpate
但是Update会在每次渲 染新的一帧时被调用. 而FixedUpdate会在每个固定的时间间隔被调用,
- Oracle 中的游标(用Javase中Iterator 类比之)
当使用 pl/sql 查询 Oracle 数据库时,有时我们想输出多条记录的数据.:select * from scott.emp; 这时,我们一定会想利用循环来输出.但是,在pl/sql 中是没有数 ...
- 201453408刘昊阳 《Java程序设计》第5周学习总结
201453408刘昊阳 <Java程序设计>第5周学习总结 教材学习内容总结 第8章 异常处理 8.1 语法与继承结构 8.1.1 使用try.catch p227代码(Average) ...
- JavaScript实现存储HTML字符串
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- xcode 编译opencv ios容易出现的错误
(1)出现 "std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush()"之类 ...
- transform应用详解
关于css3的transform,做了一个demo,上代码 html: <!DOCTYPE html> <html> <head lang="en"& ...
- SQL中union运算操作的理解
在SQL中,对于并运算,可以使用union关键字. 例如: SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FRO ...
- 你用java的swing可以做出这么炫的mp3播放器吗?
这个mp3播放器是基于java的swing编写的,我认为界面还是可以拿出来和大家看一看评一评. 先说说创作的初衷,由于前段时间工作不是很忙,与其闲着,还不如找一些东西来给自己捣腾捣腾,在 之前写的 j ...
- OSG 自定义数据类型 关键帧动画
OSG 自定义数据类型 关键帧动画 转自:http://blog.csdn.net/zhuyingqingfen/article/details/12651017 /* 1.创建一个AnimManag ...
- validation插件
1.项目下载地址:http://plugins.jquery.com/validation/ 2.引入 <script type="text/javascript" src= ...