我似乎找不到正确的语法来使用 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"
And
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'
And
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'
And
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'