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

前端 未结 7 965
星月不相逢
星月不相逢 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条回答
  •  Happy的楠姐
    2021-02-08 22:21

    I guess your goal was to clearly seperate field values by using an unique identifier so that import procedure doesn't have an issue.

    I had same issue and found this workaroud useful: Using an unusual field terminator, for example | or even a string /#/ can be very unique and shouldn't mess with your string content. You also can HEX-Values (limited, see https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-2017)

    export

    bcp DB.dbo.Table out /tmp/output2.csv -c -t "/#/" -U sa -P secret -S localhost
    

    import

    bcp TargetTable in /tmp/output2.csv -t "/#/" -k -U sa -P secret -S localhost -d DBNAME -c -b 50000 
    

提交回复
热议问题