日期:2014-05-18 浏览次数:20384 次
USE [Hitachi] GO CREATE PROCEDURE [dbo].[ExcelTemp] @strCmd nvarchar(200) AS BEGIN EXEC master..xp_cmdshell 'bcp "@strCmd" queryout D:\Temp1.xls -c -q -S"HMPC07018" -U"sa" -P"123456"' END ----------创建完成 exec [ExcelTemp] 'select * from Hitachi.dbo.Users' --Error = [Microsoft][SQL Native Client][SQL Server]必须声明标量变量 "@strCmd"。
EXEC master..xp_cmdshell 'bcp "'+@strCmd+'" queryout D:\Temp1.xls -c -q -S"HMPC07018" -U"sa" -P"123456"' --字符串拼接
------解决方案--------------------
create procedure pp @strcmd nvarchar(200) as begin exec('exec master..xp_cmdshell ''bcp '+@strcmd+' out d:staff.xls -c -q -S . -U sa -P sa '' ') end exec pp 'mydb.dbo.tb'