Skip to content
Advertisement

Sql server not updating records with nested case statement in a query

I’m using sql server 2012 and here is my query:

update  tablename set column1=case
when  column2 is null or column2=''  then '1st' 

when  column3 like 'Information%'  and 
(DATEDIFF(YEAR,convert(datetime,column6,103),getdate())) not IN (18,19,20,21)  then '2nd a' 


when  column3 not like 'Information%' and (DATEDIFF(YEAR,convert(datetime,column6,103),getdate())) 
not IN (21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40) then '2nd b'  

when column4 not like '%[^0-9]%' and 
CAST(replace(replace(column5,',',''),'','0') as bigint)
< 10*CAST(CAST((replace(ISNULL(REPLACE(column5,'','0'),'0'),',','')) as float) as bigint)/100  and column12='1' 
then '3rd a'  


when column4 not like '%[^0-9]%' and 
CAST(replace(replace(column5,',',''),'','0') as bigint)
< 20*CAST(CAST((replace(ISNULL(REPLACE(column5,'','0'),'0'),',','')) as float) as bigint)/100  and column12='2' or column12='3' 
then '3rd b'  


when  UPPER(column20)='YES'  or column20='Yes' or column20='Unknown' then '4th' 


when   column15<>'' and column15  not in (select  column2 from  table2) and 
CAST((replace(ISNULL(column15,'0'),',','')) as int) <1000000 
then '5th' 
else  null
end
,  

column2=
case
when    column1='1st'     then  'Rejected Reason'
when    column1='2nd a'   then  'Rejected Reason'
when    column1='2nd b'   then  'Rejected Reason'
when    column1='3rd a'   then  'Rejected Reason'
when    column1='3rd b'   then  'Rejected Reason'
when    column1='4th'     then  'Rejected Reason'
when    column1='5th'     then  'Rejected Reason'
else null end , column10=1  where column11=null

it isn’t update my table just results

(0 row(s) affected)

couldn’t configure the issue even i tried a single query just like

update  tablename set column1=case
when  column2 is null or column2=''  then '1st' 
else  null
end
where column11=null

is there something which I’m doing wrong? or any other way to achieve my desired result?

Advertisement

Answer

 where column11=null

is mandatory to write WHERE Column11 IS NULL

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement