简体   繁体   English

SQL Server将数据导出到CSV换行符

[英]SQL server export data to csv break line

I'm using SQL server 2008 我正在使用SQL server 2008
I wrote a batch that exports store procedure resultes into csv file: 我写了一个将存储过程结果导出到csv文件的批处理:

sqlcmd -S MyServer -d MyTable -E -Q "dbo.MySPname" -o "c:\\textfile4.csv" -h-1 -s"," -w 999 -W

1. When I open the output csv file I saw a break line in the middle of the row, like: 1.打开输出的csv文件时,在行中间看到一个换行符,例如:

[Row 1]
[line 1]:  col1_val, col2_val, col3_val, [line break]
[line 2]:  col3_val,....

[Row 2]
[line 3]:  col1_val, col2_val, col3_val, [line break]
[line 4]:  col3_val,....
  1. And there are now headers. 现在有标题。

Whats wrong with my export? 我的出口怎么了?

It was a line break in one of the fields 这是其中一个领域的换行符
I solve that by adding 我通过添加解决

SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM