SQL Server BCP: How to put quotes around all fields?

前端 未结 7 933
星月不相逢
星月不相逢 2021-02-08 22:01

I have this BCP command:

\'bcp DBName..vieter out c:\\test003.txt -c -T /t\"\\\",\\\"\" -S SERVER\'

The output CSV I get does not put quotes ar

7条回答
  •  -上瘾入骨i
    2021-02-08 22:39

    Setting the row terminator in addition to the field terminator should do the trick

    'bcp DBName..vieter out c:\test003.txt -c -T -t"\",\"" -r"\"\n\"" -S SERVER'
    

    This will likely work, but miss off the leading " for the first field of the first line, and perhaps the last field of the last line - I'm not sure, just guessing really, no server here!

    or try using QUOTENAME to wrap text fields (you could also wrap numbers, but that isn't normally required.)

    'bcp "SELECT id, age, QUOTENAME(name,'"') FROM DBName..vieter" queryout c:\test003.txt -c -T -t"," -S SERVER'
    

提交回复
热议问题