我有以下存储过程将数据复制到文本文件:
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
ALTER Procedure BCP_Inv_Text_File
(
@FileName varchar(100),
@DocDate varchar(10)
)
as
Declare @str varchar(1000)
Declare @SQL varchar(1000)
set @SQL = 'Select T0.DocNum, T0.DocDate FROM Demo88..OINV T0 WHERE DocDate = @DocDate'
set @str='Exec Master..xp_Cmdshell ''bcp "'+@SQL+'" queryout "'+@FileName+'" -T -c'''
Exec(@str)
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
然后我希望能够执行与此类似的过程:
EXEC BCP_Inv_Text_File 'C:\Export\Inv.txt', '8/9/2013'
我收到以下错误:
Error = [Microsoft][SQL Native Client][SQL Server]Must declare the scalar variable "@DocDate".