Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
srivatsahg
Yak Posting Veteran
71 Posts |
Posted - 2009-07-07 : 04:10:06
|
Hello AllMy task is to have a conditional statement inside a stored procedure.The results returned should depend on the parameters i send.However Im not able to execute these stored procedures or functions because of the syntax errorsInside stored procedure(say usp_MyProc) i have something like this...If @flag = 0 SELECT Col1 from X //@flag(bit) is an input parameterElse SELECT Col1 from Y I get an error when i use the procedure inside a case statementSelect SomeColA,SomeColB = CASE [tablenumber]WHEN 1 THEN usp_MyProc 1WHEN 0 THEN usp_MyProc 0ENDFROM SomeTableCould anyone tell me how to execute stored procs or functions in such a scenario ?RegardsSrivatsa |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-07 : 04:19:01
|
| ??? how can you select 'usp_proc' inside 'some table'?or maybe im wrong...please guideAMITOFO+AMEN+YA ALLAH Hope the query works |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-07 : 04:23:03
|
quote: I get an error when i use the procedure inside a case statementSelect SomeColA,SomeColB =CASE [tablenumber]WHEN 1 THEN usp_MyProc 1WHEN 0 THEN usp_MyProc 0ENDFROM SomeTable
You can execute stored procedure from a SELECT query. You will need to perform some sort of loop (while or cursor) and execute the stored procedure within the loop. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
srivatsahg
Yak Posting Veteran
71 Posts |
Posted - 2009-07-07 : 04:40:26
|
Hello Actually the following query works if i use functions instead of stored procedures. However if i use stored procedure i am not able to execute it. I just wanted to know whether we can use the stored procedures in this way.RegardsSrivatsa quote: Originally posted by khtan
quote: I get an error when i use the procedure inside a case statementSelect SomeColA,SomeColB =CASE [tablenumber]WHEN 1 THEN usp_MyProc 1WHEN 0 THEN usp_MyProc 0ENDFROM SomeTable
You can execute stored procedure from a SELECT query. You will need to perform some sort of loop (while or cursor) and execute the stored procedure within the loop. KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-07-07 : 04:44:23
|
| no you can't use sp this wayyou select functions but execute spin our current case it would be best to stick to functions |
 |
|
|
|
|
|