Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

In sql server i need to update a single column based on the condition using
case statement..
I need to concat the reason to my reason column every time when the condition fails


I tried like this....


update tbltemp set reason=
case
when len(abc)>17 then reason.concat(reason,'abc not valid')
when len(def)>100 then reason.concat(reason,'def not valid')
else ''
end


at the end i need to display reason like 'abc not valid,def not valid'
if the two conditions fails.


For the above query iam getting error like this:

Cannot find either column "reason" or the user-defined function or aggregate "reason.concat", or the name is ambiguous.
Thanks for any help in advance..
Posted
Comments
PIEBALDconsult 6-Dec-13 1:21am    
You probably need to test for >100 before testing for >17 .
And you can nest CASEs if you need to.
And use s=s+t . In fact, try s = s + CASE ... END
njdcjk 6-Dec-13 8:21am    
can u explain in detail

Try this below query.

SQL
  update tbltemp  set reason=
case 
when len(abc)>17 then reason+'abc not valid'
when len(def)>100 then reason+'def not valid'
else '' 
end 
 
Share this answer
 
Comments
njdcjk 6-Dec-13 6:33am    
I tried but it's not working..reason is still null only
Ganesh Raja 6-Dec-13 7:02am    
i have verified and this working fine when that particular condition (Length) is satisfied.
njdcjk 6-Dec-13 8:08am    
I have tried again.But still it's not working..
It will work when something is there in remarks column.If remarks column is null it will not work..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900