I am trying to execute a THROW statement like so ( value
and 12345
being some random values):
use testdb;
go
begin try
if('value' in (select distinct shelf from itemloc))
update itemloc
set shelf = 'value'
where item = '12345';
end try
begin catch
;Throw 160073, 'Failed to update shelf value', 1;
end catch;
Using this reference
I looked at this question and I have the ;
before my THROW
. I'm also checking the syntax against the reference and fail to see why executing this returns
Msg 102, Level 15, State 1, Line 11 Incorrect syntax near 'Throw'.
2条答案
按热度按时间ruyhziif1#
You're inside a
CATCH
, you can't choose your error here, you would just useTHROW;
. Also, you don't need to start your statement with a semicolon, you already put one at the end of your last statement. It's a terminator (it goes at the end of the line), not at the beginning and end.If you want to use a custom error, use
RAISERROR
. For example:e5njpo682#
Add colons,