Home > Net >  How can I use case when as well as where in sql
How can I use case when as well as where in sql

Time:08-31

This is my query but there is an error - 'INCORRECT SYNTAX NEAR WHERE'

how should i proceed

UPDATE UpdateChecker
Set UPDATED = Case   
WHEN Datediff(DAY, CURRENT_TIMESTAMP, (SELECT TOP(1) ['Debt Market Data$'].Date From ['Debt Market Data$'] ORDER BY Date Desc)) = 0 
THEN 'YES'
ELSE 'NO'
WHERE  [TABLE NAME]='Debt Market Data$'
END

CodePudding user response:

You just have to put your where after the case when ... end clause.

update UpdateChecker
set updated = case when ... then 'YES' else 'NO' end
where ....
  • Related