EXEC master..xp_cmdshell 'bcp "临时表名" out c:\DT.txt -c -Sservername -Usa -Ppassword'

解决方案 »

  1.   

    比如说用
    select * into #temp from 表名
      

  2.   

    不过你也可以直接用
    EXEC master..xp_cmdshell 'bcp "select * from table" queryout "c:\DT.txt" -c -Sservername -Usa -Ppassword'
      

  3.   

    --实践证明,可以直接这样做:EXEC master..xp_cmdshell 'bcp "exec 数据库名..存储过程名" queryout "c:\test.txt" /c /U"用户名" /P"密码"'
      

  4.   

    --要执行的简单存储过程
    create proc p
    as
    select * from 地区资料
    go--导出存储过程执行结果
    exec master..xp_cmdshell 'bcp "exec 客户资料..p" queryout "c:\a.txt" /c /P""'
    go--删除测试的存储过程
    drop proc p/*--测试结果
    output     
    ---------------------------
    NULL
    开始复制...
    NULL
    已复制了 19 行。
    数据包的大小(字节): 4096
    时钟时间(毫秒): 共      1
    NULL(所影响的行数为 7 行)
    --*/