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-% ...
随机推荐
- BZOJ4113 : [Wf2015]Qanat
设$f_i$表示用$i$个辅助井时代价的最小值,$x_i$表示此时最后一个辅助井的位置. 则$f_i$是关于$x_i$的一个二次函数,其中系数跟$f_{i-1}$有关,递推求出极值点即可. 时间复杂度 ...
- 【HDU3652】B-number 数位DP
B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose de ...
- [Cocos2d-x For WP8]Layer 层
层(CCLayer) 从概念上说,层就是场景里的背景. CCLayer同样是CCNode的子类,通常用addChild方法添加子节点.CCLayer对象定义了可描绘的区域,定义了描绘的规则.C ...
- JSP 基础概念归纳 5分钟看完
1. 符合 j2ee 标准的 web-app 的目录结构 WEB-INF classes web.xml lib servlet 开发过程 从 httpservlet 继承, 重写 doget / d ...
- codeforces589J 简单dfs,队列
J. Cleaner Robot time limit per test 2 seconds memory limit per test 512 megabytes input standard in ...
- 访问google,youtube
一.找到host文件 windows : C:\windows\system32\drivers\etc mac os: /private/etc linux : /etc 二.修改host文件 ht ...
- docker 报错Failed to start Docker Storage Setup. 的处理基本都是容器满了
:: localhost docker-storage-setup: Volume group extents): required. Apr :: localhost systemd: docker ...
- DataGridView 中添加CheckBox和常用处理方式 .
DataGridView 中添加CheckBox和常用处理方式 文章1 转载:http://blog.csdn.net/pinkey1987/article/details/5267934 DataG ...
- Windows Phone 8 MVVM
Why? 1 reason MVVM works really well with XAML based applications is because of the powerful XAML bi ...
- github的git.exe的目录所在
github的git.exe位于 C:\Users\[username]\AppData\Local\GitHub\PortableGit_25d850739bc178b2eb13c3e2a9faaf ...