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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 whats wrong with this syntax..

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 value
of 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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-10-02 : 11:33:56
but case is allowed in the QUERY itself ??

Go to Top of Page

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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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]
Go to Top of Page

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)
Else
print ''


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -