Sharktooth Sharktooth - 6 months ago 9
SQL Question

Can I update two fields in a single set statement?

I am trying to update a flag and a remark field using a case statement:

update [TEMP]
set FLAG =
(
case when len(Country) > 3 or len(country) < 3 --or len(country) = 0
then 0 else 1
case when
)


I also want to update the field remark with 'Invalid Country' for the first case statement and then 'Invalid date' for the next case statement.

Answer
update [TEMP] 
set FLAG = 
(
case when len(Country) != 3 --or len(country) = 0
then 0 else 1 end
),
date = (case when date < getDate() then getDate() else null end ),
remark = 
( case when len(Country) != 3 then 'Invalid Country'
   when date < getDate() then 'Invalid date'
   else null end)