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
 incorrect syntax error for nested (case) query

Author  Topic 

learning_grsql
Posting Yak Master

230 Posts

Posted - 2012-08-19 : 14:11:46
I created the following nested case query but it shows error "incorrect syntax near the keyword case'



select date, (case when qty1 <> 0 Then 'xyz'
case when qty2 <> 0 Then 'abc'
case when qty3 <> 0 Then 'mnt'
case when qty4 <> 0 Then 'ved' else 0
end end end end) as neworganisation from tbltable

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-19 : 14:25:48
it should be this


select date, case when qty1 <> 0 Then 'xyz'
when qty2 <> 0 Then 'abc'
when qty3 <> 0 Then 'mnt'
when qty4 <> 0 Then 'ved'
else 0
end as neworganisation
from tbltable


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

learning_grsql
Posting Yak Master

230 Posts

Posted - 2012-08-19 : 16:28:32
Thanks visakh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-19 : 21:26:57
you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -