Skip to content
Advertisement

Selecting specified query from multiple select statement inside a single stored procedure

Good Day everyone!

I’ve been searching everywhere on how to get a specified query using if-else statement inside a single stored procedure but still no luck on how to achieve those function.

Here’s the T-Sql

When exec command is called, it only return Command(s) completed successfully instead the value/table of the selected command. Since the @action is null, it should return the following query and when @ action is supplied with value, it should return the 2nd query.

When if-else statement is removed, it returns the first query but there’s no means of accessing the 2nd query.

I saw this method here.

Thank you and I appreaciate any help that this post can get.

Advertisement

Answer

You would need to print the variable to the value of the variable @action. Eg:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement