Using MS SQL Server 2016..
I am trying to stop execution of a SQL script when a condition is met and it is not working. At first I thought i could use RAISERROR, then it appears that only works when the moon is full and Trump says something intelligent. Then I tried RAISERROR with RETURN and that wasn't much more help..
So, it seems I should be using TRY/CATCH as RAISERROR will give differing results depending on severity levels. So, completely do not understand how to use this. I have looked up examples and tried, but each one i have tried the script does not stop executing..Per a suggestion from the web, it says to make your BEGIN statement, then BEGIN TRY and under that your condition and the END TRY and then BEGIN CATCH which it appears to reference what was in BEGIN TRY? And then END CATCH and then END.
But that doesn't seem to work, so would appreciate some help! Here is what i have that doesn't work based on trying to replicate what the web page said, though clearly I'm missing something..Note, the declarations are in the beginning of the script and so not going to declare them again..
SET @NbrOfUsersGiven = (SELECT COUNT(*) FROM #USERSGIVEN)
IF @ROLE IN ('VR Champion', 'VR Project Lead', 'VR Business Analyst') AND @NbrOfUsersGiven > 1 RAISERROR (N'Nothing Processed. You appear to have more than one user id for the role of either VR Champion, VR Project Lead or Business Analyst', 16,1)
RAISERROR (N'Nothing Processed. You appear to have more than one user id for the role of
either VR Champion, VR Project Lead or Business Analyst', 16,1)