EXEC master..xp_cmdshell 'bcp dbname..tablename out c:\DT.txt -c -Sservername -Usa -Ppassword' 
或 
EXEC master..xp_cmdshell 'bcp "Select * from dbname..tablename" queryout c:\DT.txt -c -Sservername -Usa -Ppassword'

解决方案 »

  1.   

    需要开启xp_cmdshell --是否允许运行系统存储过程xp_cmdshell
    sp_configure 'show advanced options',1
    reconfigure
    go
    sp_configure 'xp_cmdshell',1
    reconfigure
    go
    sp_configure 'show advanced options',0
    reconfigure
    go
      

  2.   

    运行结果并没有输出我想要的结果,而是输出了BCP如何使用的14行字段。
      

  3.   

    exec master..xp_cmdshell 'bcp "库名..表名" out "d:\tt.txt" -c -t ,-U sa -P password'这样没有?
      

  4.   

    我是按照xp_cmdshell再次执行的。
      

  5.   


    exec master..xp_cmdshell 'bcp "select ''Cust_nbr'' Cust_nbr,''Acc_nbr'' Acc_nbr union all select Cust_nbr,Acc_nbr from [数据库名].dbo.pz14_yd" queryout [txt文件名] -S "[服务器名]" -U "[账号]" -P "[密码]" -c -t "," '