简体   繁体   中英

SQL server export data to csv break line

I'm using SQL server 2008
I wrote a batch that exports store procedure resultes into csv file:

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:

[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), '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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