使用语句导出查询结果吧:执行导出语句前先执行着一段代码:
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 之后再执行下面的语句,当然你得修改将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"'

解决方案 »

  1.   

    可能是你数据里的内容与excel格式特定的解析字符冲突导致的,
    具体要查看你那几条错误数据的内容,看看如何替换及避免。
    可以试试直接导入到txt,看看那几条数据是否有问题就知道是不是excel的问题了。
      

  2.   

    已经解决。原因是某一列有双引号和空格,造成复制到excel出错。
      

  3.   

    可能是你的数据里包含某些特殊符号,而这些特殊符号在excel里面有其他的定义,比如一个"在excel里面就是文本分隔符。
    你重点检查错误或空行的记录,是否存在这种符号。
      

  4.   

    可能是数据里包含回车或换行符。在sqlserver里用replace(内容,char(10),'')替换掉就可以了。char(10)表示换行,char(13)表示回车。