请教
select * from table where title = '123'
怎么将这个 语句查询的内容导为xls, 是用命名,不是 手工导出。

解决方案 »

  1.   


    将SQL SERVER中查询到的数据导成一个Excel文件
    T-SQL代码:
    EXEC master..xp_cmdshell 'bcp 库名.dbo.表名out c:\Temp.xls -c -q -S"servername" -U"sa" -P""'
    参数:S 是SQL服务器名;U是用户;P是密码EXEC master..xp_cmdshell 'bcp axzq.dbo.Staff out d:staff.xls -c -q -S"." -U"sa" -P"gazx"'说明:还可以导出文本文件等多种格式
    实例:EXEC master..xp_cmdshell 'bcp saletesttmp.dbo.CusAccount out c:\temp1.xls -c -q -S"pmserver" -U"sa" -P"sa"'
    EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout C:\ authors.xls -c -Sservername -Usa -Ppassword'EXEC master..xp_cmdshell 'bcp "select name from axzq..staff order by name"  queryout d:staffName.xls -c -q -S"." -U"sa" -P"gazx"'
      

  2.   

    谢1楼我用的EXEC master..xp_cmdshell 'bcp "select name from axzq..staff order by name"  queryout d:staffName.xls -c -q -S"." -U"sa" -P"gazx"'
    但是我导出来的xml没有 字段的列名 怎么解决呢?
      

  3.   

    但是我导出来的 xls 没有 字段的列名 怎么解决呢?
      

  4.   

    EXEC master..xp_cmdshell 'bcp "select name from axzq..staff where name like'%J%'" queryout d:staffName.xls -c -q -S"." -U"sa" -P"gazx"'
    这样会报错,,like'%J%'
    怎么解决
      

  5.   

    EXEC master..xp_cmdshell 
    'bcp "select name from axzq..staff where name like''''%J%''''" 
    queryout d:staffName.xls -c -q -S"." -U"sa" -P"gazx"'
      

  6.   

    那是类型的问题。你的这几个字段是不是int型或者float?你把它转换长字符串再往外导出
      

  7.   

    我这样写的
    cast(sfzh as varchar(18)) as 身份证还是不行。
      

  8.   

    现在身份证这个字段就是 字符的sfzh nvarchar(255)
      

  9.   

    这个我也不怎么清楚,你试试varchar(18)这个类型