【发布时间】:2013-08-26 19:50:22
【问题描述】:
在这个存储过程中,我从名为M_SopInsert 的第三方供应商表中读取数据。
SQLScript 是列名,此表中的每条记录都包含一个 SQL 查询,该查询执行 UPDATE、INSERT 或 DELETE。
当我使用 Select 调试它时,我可以看到实际的脚本(在下面评论)。但是脚本本身没有执行,我没有看到任何错误。
我尝试硬编码下面的UPDATE 语句,它工作正常。
这可能是什么问题?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
declare @sopScript nvarchar(1000)
select SQLScript into #ControlTbl from M_SopInsert
where soptype = @I_vSOPTYPE and sopnumbe = @I_vSOPNUMBE and lnitmseq = @I_vLNITMSEQ
while exists (select * from #ControlTbl)
begin
select top 1 @sopScript = SQLScript
from #ControlTbl
--exec executesql @sopScript = SQLScript
--select @sopScript
--EXEC sp_executesql @sopScript;
--EXEC sp_executesql "update SOPQty set QTYORDER = '17.89' where LNIT = '16'"
exec sp_executesql @sopScript = SQLScript
delete from #ControlTbl where SQLScript = @sopScript
end
drop table #ControlTbl
return (@O_iErrorState)
【问题讨论】:
-
你说你已经更正以使其工作的语法错误应该产生
Msg 2812, Could not find stored procedure 'SQLScript'.- 这是所有代码,还是包裹在TRY/CATCH或其他东西中?
标签: stored-procedures sql-server-2008-r2 while-loop sql-update sp-executesql