我正在努力使我的try/catch可以与我的存储过程一起使用,但似乎无法捕获该错误。我一直在搜寻,但没有运气。我要完成的工作是,如果在调用存储过程时给出了无效值,无值或空值,则显示错误号。我尝试过尝试并捕获它的感觉到处都是,但是似乎错误可能在“@SomeID as int”行上。感谢您能获得的任何帮助。
alter procedure DeleteAcct
@SomeID as int
as
begin try
declare @counter int
set @counter = (select count(SomeDate) from Table1 where SomeID = @SomeID group by SomeID)
begin
if(@counter > 0)
begin
Print 'Testing'
end
else
begin
delete from Table2
where SomeID = @SomeID
Print 'Delete successful'
end
end
end try
begin catch
print error_number()
end catch
<!-- calling the stored procedure -->
exec DeleteAcct '1231231231221'
<!-- Error received -->
Msg 8114, Level 16, State 5, Procedure DeleteAcct, Line 0
Error converting data type varchar to int.
最佳答案
您将param @SomeID
声明为int
,然后尝试传递字符串!
像这样拨打电话:
exec DeleteAcct 1231231231221
实际上,我怀疑
@SomeID
应该声明为varchar
关于stored-procedures - 尝试/捕获无法捕获存储过程中的异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28781036/