在查询分析器里,如何用sql语句导出数据生成TXT格式?

解决方案 »

  1.   


    EXEC master..xp_cmdshell 'BCP  "select × from db.dbo.tb"  queryout c:\tb.txt -c -S -T'
      

  2.   

    EXEC master..xp_cmdshell 'BCP 表明 in(out)(queryout) 路径 -c -S"servername" -T'
      

  3.   

        bcp 库名..表名 out c:\a.txt -U用户名 -P密码 -SIP地址 -n -c  --将某表的内容导出到txt文件中     bcp 库名..表名 in c:\a.txt -U用户名 -P密码 -SIP地址 -n -c  --将txt文件中的内容导入到某表中 
        bcp "select * from 表名 where 条件" queryout c:\a.xls -U用户名 -P密码 -SIP地址 -n -c  --将某表中符合条件的记录导出到Excel文件中 
      

  4.   

    SQLState = 08001, NativeError = 17
    Error = [Microsoft][ODBC SQL Server Driver][Shared Memory]SQL Server 不存在或访问被拒绝
    SQLState = 01000, NativeError = 2
    Warning = [Microsoft][ODBC SQL Server Driver][Shared Memory]ConnectionOpen (Connect()).
    NULL出现这个是什么问题呢
      

  5.   

    /** 导入文本文件 */
    EXEC master..xp_cmdshell 'bcp dbname..tablename in c:\DT.txt -c -Sservername -Usa -Ppassword' /** 导出文本文件 */
    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' /**导出到TXT文本,用逗号分开*/ 
    exec master..xp_cmdshell 'bcp "库名..表名" out "d:\tt.txt" -c -t ,-U sa -P password' 
    BULK INSERT 库名..表名 
    FROM 'c:\test.txt' 
    WITH ( 
    FIELDTERMINATOR = ';', 
    ROWTERMINATOR = '\n' 
      

  6.   

    EXEC master..xp_cmdshell 'bcp dbname..tablename in c:\DT.txt -c -Sservername -Usa -Ppassword' 这个试了好多次都不得,不知道为什么
      

  7.   

    EXEC master..xp_cmdshell 'bcp master..balibe out c:\DT.txt -c -Sservername -Usa -Ppassword' 这样对不
      

  8.   

    你的servername, password是否用真实环境的数据替换了?
      

  9.   

    楼主,前面的几位是给出了调用的模式,具体到执行的时候你得把语句中的参数换成你自己本地的参数,例如
    EXEC master..xp_cmdshell 'bcp mydatabase1..mytable1 out e:\DT.txt  -c -S 192.168.0.202 -U sa -P sa123'
      

  10.   

    你连接的服务器名字是叫做"servername", 还是你实际执行的命令已经将serservername替换为真实的名字了?
    同理,你的"password"?
      

  11.   

    忘了跟楼主说了,第一次执行xp_cmdshell的时候,SqlServer会阻止对xp_cmdshell的访问,因为此组件已作为此服务器安全配置的一部分而被关闭,楼主运行下面的代码就OK了:-- To allow advanced options to be changed.
    EXEC sp_configure 'show advanced options', 1
    GO
    -- To update the currently configured value for advanced options.
    RECONFIGURE
    GO
    -- To enable the feature.
    EXEC sp_configure 'xp_cmdshell', 1
    GO
    -- To update the currently configured value for this feature.
    RECONFIGURE
    GO
      

  12.   

    最简单的方法查询出来 右键另存为 .txt文件