View Full Version : Problems with Update...Case Statement


GrahamK
06-01-2009, 05:09 AM
Hello All,

I'm trying to run the query Below on SQL Server 2000 and and getting the error "Line 4: Incorrect syntax near '=' " I wonder if anyone can offer assistance?


UPDATE tblStaffQual
SET Status =
(CASE
WHEN GETDATE() >= Expires_Date THEN Status = 'Expired'
WHEN GETDATE() < (Expires_Date-90) THEN Status = 'Current'
ELSE (Status = 'Approaching')
END
);


Many Thanks
Graham

pbaldy
06-01-2009, 07:10 AM
For starters, this is the kind of thing that should not be stored, rather calculated on the fly as needed. You would have to run this every day to keep things current. That said, the syntax would be:

WHEN GETDATE() >= Expires_Date THEN 'Expired'

GrahamK
06-01-2009, 08:11 AM
For starters, this is the kind of thing that should not be stored, rather calculated on the fly as needed. You would have to run this every day to keep things current. That said, the syntax would be:

WHEN GETDATE() >= Expires_Date THEN 'Expired'

Paul,

Thank you very much for your assistance!

Graham