【发布时间】:2018-01-25 01:09:59
【问题描述】:
我似乎找不到正确的语法来使用 sql server management studio 中的 exec xp_cmdshell bcp 导出具有列名的数据。我尝试了以下变体
EXEC xp_cmdshell bcp "select "a_id","b_id","c_id" union select a_id,b_id,c_id from tablename out
"\\network_path\a.txt" -c -Uusername -Ppassword -Sservername"
还有
EXEC xp_cmdshell bcp 'select 'a_id','b_id','c_id' union select a_id,b_id,c_id from tablename out
'\\network_path\a.txt' -c -Uusername -Ppassword -Sservername'
和
EXEC xp_cmdshell bcp 'select "a_id","b_id","c_id" union select a_id,b_id,c_id from tablename out
"\\network_path\a.txt" -c -Uusername -Ppassword -Sservername'
和
EXEC xp_cmdshell bcp "select 'a_id','b_id','c_id' union select a_id,b_id,c_id from tablename out
'\\network_path\a.txt' -c -Uusername -Ppassword -Sservername"
我已成功使用以下命令导出表格,但我还需要列名。
bcp tablename out "\\network_path\a_test.txt" -c -Uusername -Ppassword -Sservername'
【问题讨论】:
标签: sql-server bcp xp-cmdshell