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 |
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-10-02 : 11:29:19
|
| [CODE]CASE field_val WHEN 'M5' THEN EXEC ( @query) ELSE THEN print '' END[/CODE]I have a SP , and i state a query .. but i only want this query to be executed based on the valueof field_val , otherwise i print a blank ..but when i check the syntax (ms sql server 2000) i get "invalid syntax near CASE .. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-02 : 11:32:04
|
| Condition execution using CASE is not allowed in SQL Server.Why don't you go for straight forward IF..ELSE?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-10-02 : 11:33:56
|
| but case is allowed in the QUERY itself ?? |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-02 : 11:37:18
|
| Yes CASE is allowed in query but dynamic execution of other query using EXEC with CASE is not allowed.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-10-02 : 11:40:46
|
| ok so i should have something like :[CODE]IF field_val = 'M5' THEN EXEC (@Query)ELSE PRINT ''[/CODE] |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-02 : 11:59:36
|
No.If Exists(select * from table where field_val = 'M5')EXEC(@query)Elseprint '' Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|