需要帮助,因为我如何捕获与在存储过程中执行sql脚本有关的任何错误。
select sopScript
from M_SopInsert
where soptype = @soptype and sopnumbe = @sopnumbe and lnitmseq = @lnitmseq
If result_count > 0 //if result from above sql query is >0
exec sopScript //loop through the record set and execute sopscript for every record.
注意:此处的sopscript包含以下脚本:
update customerMaster
set custname='abc'
where custid=100`"
最佳答案
本来误读了问题。
尝试使用
declare @sopScript varchar(1000)
select sopScript
into #ControlTbl
from M_SopInsert
where soptype = @soptype and sopnumbe = @sopnumbe and lnitmseq = @lnitmseq
while exists (select * from #ControlTbl)
begin
select top 1 @sopScript = sopScript
from #ControlTbl
begin try
exec executesql @sopScript = sopScript
end try
begin catch
*do something*
end catch
delete from #ControlTbl
where sopScript = @sopScript
end
关于sql-server-2008 - 需要帮助在存储过程中执行sql脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18446261/