如何调用SqlServer200导出数据到Excel的存储过程?

cfqmxh 2004-10-29 11:30:40
我的存储过程是:
CREATE proc dbo.export(@dbname nvarchar(1000))
as
declare @s varchar(8000)
set @s='bcp '+@dbname+' out c:\ls.xls -c -q -S"(cfq)" -U"" -P""'
exec master..xp_cmdshell @s
GO
然后在SQL查询分析器中我该怎样调用这个存储过程呢?谢谢!
...全文
144 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cfqmxh 2004-10-29
  • 打赏
  • 举报
回复
问题解决!
非常感谢!
结贴!
zjcxc 元老 2004-10-29
  • 打赏
  • 举报
回复
--少写了"
CREATE proc dbo.export(@dbname nvarchar(1000))
as
declare @s varchar(8000)
set @s='bcp "'+@dbname+'" queryout c:\ls.xls -c -q -S"(cfq)" -U"" -P""'
exec master..xp_cmdshell @s
GO

cfqmxh 2004-10-29
  • 打赏
  • 举报
回复
我改了存储过程了然后用:
exec dbo.export 'Select * from aa.dbo.Field'
怎么老是报下面的错:
复制方向必须是 'in'、'out' 或 'format'。
用法: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"]
NULL


officecn 2004-10-29
  • 打赏
  • 举报
回复
直接执行就行了,存储过程可以当做普通的SQL来执行。
rivey 2004-10-29
  • 打赏
  • 举报
回复
exec dbo.export 'Select * from dbname.dbo.job'
zjcxc 元老 2004-10-29
  • 打赏
  • 举报
回复
--那就要改存储过程
CREATE proc dbo.export(@dbname nvarchar(1000))
as
declare @s varchar(8000)
set @s='bcp '+@dbname+' queryout c:\ls.xls -c -q -S"(cfq)" -U"" -P""'
exec master..xp_cmdshell @s
GO
cfqmxh 2004-10-29
  • 打赏
  • 举报
回复
如果我要代入的参数是一SQL语句那我该咋办?
是:exec dbo.export 'Select * from jobs'吗?
是不是存储过程中的out要改成queryout?
不过我这样改了也不行!出如下错:
复制方向必须是 'in'、'out' 或 'format'。
用法: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"]
NULL


zjcxc 元老 2004-10-29
  • 打赏
  • 举报
回复
--调用
exec dbo.export 'pubs.dbo.jobs'

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧