Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

Compare parameter to table value, and either continue or stop procedure

$
0
0

I am creating a stored procedure that generates a different output depending on an @Country parameter. In one of the tables that I am using there is an ID field that is a 3 digit number, this 3 digit number is a country ID. Is there a way to compare my @Country parameter to that ID field, and if it matches continue running the procedure, but if it does not match to stop? 

For example if my ID field is 118 (3 digit ID for the UK) and my parameter is set as UK I want the procedure to run. If my ID field is 119 (3 digit ID for France) and my parameter is set as UK, I want the procedure to stop. 

I thought about using UPDATE in the procedure to change the ID field to match what the parameter would provide, but there are a couple of countries that use the same ID field. Asia Pacific uses the same 3 digit ID, but there are multiple countries each of which has it's own output, therefore I cannot for example update the ID field to NZ when that table is also used for Australia. I believe that could still work, I could update the ID field to APC and use something like

WHERE @Country IN ('AU','NZ') AND ID = 'APC' 

But, even assuming that would work, it still leaves me stuck at how to get the procedure to stop if there is a mismatch.

Thanks.


Viewing all articles
Browse latest Browse all 4729

Trending Articles