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

前端 未结 7 1167
星月不相逢
星月不相逢 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条回答
  •  遇见更好的自我
    2021-02-08 22:18

    Alternatively, if you are fine for Powershell based script, you can try with below code, which does automatic quoting.

    Invoke-sqlcmd -ConnectionString "Server=SERVERNAME, `
    3180;Database=DATABASENAME;Trusted_Connection=True;"  `
    -Query "SET NOCOUNT ON;SELECT * FROM TABLENAME" -MaxCharLength 700 | `
    Export-Csv -NoTypeInformation -path C:\temp\FileName.csv -Encoding UTF8
    

提交回复
热议问题