我想通过“RPT_ID = 245”从1到245循环并在try中捕获无效的查询语句,以便捕获无效的查询。
查询列是为报告创建的动态sql语句。
alter PROCEDURE usp_ExampleProc
AS
declare
@vsql2 as nvarchar(max)
,@vquery2 as nvarchar(max)
,@value as nvarchar(max)
,@value2 as nvarchar(max)
,@Q1 as nvarchar(max)
,@RP_NUM as nvarchar(max)
,@count as int
select @count = count(*) from saved_reports
while @count > 0
begin
select @q1 = query,@RP_NUM =RPT_ID from SAVED_REPORTS WHERE RPT_ID = @count
exec sys.sp_executesql @q1
BEGIN TRY
EXECUTE usp_ExampleProc;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH
set @count = @count - 1
end
答案 0 :(得分:1)