calling stored procedure in case statement - Sql Server 2000
-
Can any one please tell me how to call a stored procedure from case statement.
Thanks In Advance
-
Can any one please tell me how to call a stored procedure from case statement.
Thanks In Advance
A Case statement in SQL is an embedded part of a Select statement so you can't call a stored procedure in the middle, only a function. However I guess you mean something more like the following:
If @Test = 1
Execute [Procedure1];
Else If @Test = 2
Execute [Procedure2];
Else If @Test = 3
Execute [Procedure3];
Else
Execute [Procedure4];If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
A Case statement in SQL is an embedded part of a Select statement so you can't call a stored procedure in the middle, only a function. However I guess you mean something more like the following:
If @Test = 1
Execute [Procedure1];
Else If @Test = 2
Execute [Procedure2];
Else If @Test = 3
Execute [Procedure3];
Else
Execute [Procedure4];If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
you can also use case when for this.
-
you can also use case when for this.
You are still not going to be able to exec another proc from withing the case statement! Case and Exec() do not go together!
Never underestimate the power of human stupidity RAH
-
you can also use case when for this.
No you can't. To quote the Micosoft documentation[^]: The CASE expression cannot be used to control the flow of execution of Transact-SQL statements, statement blocks, user-defined functions, and stored procedures. For a list of control-of-flow methods, see Control-of-Flow Language (Transact-SQL)[^]. The question was regarding calling stored procedures and that is clearly not possible from within a case statement.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]