27,579
社区成员
发帖
与我相关
我的任务
分享
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"。
declare @strCmd nvarchar(200)
set @strCmd='select * from Hitachi.dbo.Users'
exec('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'
exec('exec master..xp_cmdshell ''bcp '+@strCmd+' queryout D:\Temp1.xls -c -q -S HMPC07018 -U sa -P 123456 '' ')
EXEC master..xp_cmdshell 'bcp "'+@strCmd+'" queryout D:\Temp1.xls -c -q -S"HMPC07018" -U"sa" -P"123456"'
--字符串拼接
--试试
exec('exec master..xp_cmdshell ''bcp '+@strCmd+' queryout D:\Temp1.xls -c -q -S HMPC07018 -U sa -P 123456 ')