Switch to include column headers in bcp

六月ゝ 毕业季﹏ 提交于 2019-12-24 16:29:29

问题


I don't see in the documentation how to include column headers with in my csv-type output file. I'm sure this is a duplicate, But I can't seem to find one that leads to my exact need.

Here's my command:

 bcp "select * from MYDB.dbo.MyTable" queryout "C:\outputfile.csv" -c -t"," -r"\n" -S ServerName -T -k -E

回答1:


A standard well known hack is to select the column names union all make them part of the query itself and export that, something like this......

bcp "SELECT 'ColName1','ColName2','ColName3' UNION ALL select ColName1,ColName2,ColName3 from MYDB.dbo.MyTable" queryout "C:\outputfile.csv" -c -t"," -r"\n" -S ServerName -T -k -E


来源:https://stackoverflow.com/questions/32061302/switch-to-include-column-headers-in-bcp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!