0

I'm extending a stored procedure and I have to make some code that checks if a row contains some of the following then the SP will stop at the first stip which is this one. The SP contains of 6 steps and this is the first one. Which is used as a controller to see if the row contains some if these. If it's doesent then it should continue to the next step. If it does cointain some of the following then it should leave a notice and not contiune to the next step.

if @action = (select action from dbo.table where action like 'something-%')

if @action = (select action from dbo.table where action like 'something-else%')


if @action = (select action from dbo.table where action like 'something-new%')


if @action = (select action from dbo.table where action like 'something-old%')


if @action = (select action from dbo.table where action like 'something-cool%')

I have the first part need help with the second.

Cheers

2
  • Is the next step not a RETURN statement? Commented Nov 21, 2013 at 9:17
  • you should use if...else if. Using CASE might be better Commented Nov 21, 2013 at 9:17

2 Answers 2

2

I'd just use RETURN:

if @action = (select action from dbo.table where action like 'something-%') begin
    RETURN;
end
Sign up to request clarification or add additional context in comments.

Comments

0

You can use case statement instead of many if statement.
Hope this example will Help

Simple CASE expression: 
    CASE input_expression 
         WHEN when_expression THEN result_expression [ ...n ] 
         [ ELSE else_result_expression ] 
    END 
    Searched CASE expression:
    CASE
         WHEN Boolean_expression THEN result_expression [ ...n ] 
         [ ELSE else_result_expression ] 
    END

1 Comment

Given that the results are not necessarily mutually exclusive, would that mean potentially executing all the queries needlessly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.