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

前端 未结 7 948
星月不相逢
星月不相逢 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:24

    Here are the list of commands i used .

    BCP "DECLARE @colnames VARCHAR(max);SELECT @colnames = COALESCE(@colnames + ',', '') + column_name from databaseName.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='tableName'; select @colnames;" queryout "C:\HeadersOnly.csv" -r"\n\""  -c -T -Uusername -Ppassword -SserverName
    
    bcp databaseName.schema.tableName out "C:\EmployeeDatawithoutheaders.csv" -T -t"\",\"" -r"\"\n\"" -c -Uusername -Ppassword -SserverName
    
    copy /b C:\HeadersOnly.csv+C:\EmployeeDatawithoutheaders.csv C:\EmployeeData.csv
    
    del C:\HeadersOnly.csv
    
    del C:\EmployeeDatawithoutheaders.csv
    

提交回复
热议问题