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
 Error in CASE statement

Author  Topic 

Petronas
Posting Yak Master

134 Posts

Posted - 2009-03-30 : 10:45:23
Hi,

I have the following query:


select order_received_date,cancel_date,
CASE WHEN (cancel_date is NULL THEN 1 else null END ) 'ActiveSaves',
case WHEN (cancel_date <= (order_received_date + 30) THEN 1 else null END)'Cancelledin30',
case WHEN (cancel_date > (order_received_date + 30) and cancel_date <=(order_received_date + 60)) THEN 1 else null END 'Cancelled31To60',
case WHEN ( cancel_date > (order_received_date + 180) and cancel_date <= (order_received_date + 365) ) THEN 1 else null END 'CancelledOver180',
case WHEN (cancel_date > (order_received_date + 365) THEN 1 else null END)'CancelledOver1yr'

from #Temp_Call

I am getting the following error: "Incorrect syntax near the keyword 'THEN'".
I am using SQL server 2005..

Thanks for your help,
Petronas

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-30 : 10:55:42
select order_received_date,cancel_date,
CASE WHEN cancel_date is NULL THEN 1 else null END as ActiveSaves,
case WHEN cancel_date <= (order_received_date + 3) THEN 1 else null END as Cancelledin30,

and so on...
Go to Top of Page

Petronas
Posting Yak Master

134 Posts

Posted - 2009-03-31 : 15:56:08
Thanks vijayisonly it worked...
Sorry for the late response.. was out sick.

Appreciate your help,
Petronas
Go to Top of Page
   

- Advertisement -