SQL Server Performance

UPDATE SET sql that includes case statement

Discussion in 'General Developer Questions' started by v1rtu0s1ty, May 26, 2005.

  1. v1rtu0s1ty New Member

    Hey guys,<br /><br />Is this possible? I want to update several fields base on their existing content.<br />Example,<br /><br />loannumber,firstname,lastname, and age fields and assuming their all declared as varchars<br /><br />Here is our data:<br /><br />123, john, doe, 53<br />124, frank, sinatra, 60<br />125, NULL, cowell, NULL<br />126, bob, hope, NULL<br /><br />what I would like to happen after the UPDATE SET is like this<br /><br />123, fname_123, lname_123, a123<br />124, fname_124, lname_124, a124<br />125, NULL, lname_125, NULL<br />126, fname_126, lname_126, a126<br /><br />Using SELECT statement, it's easy for me. I used this kind of CASE statement<br /><br /> firstname_mod = <br /> case when firstname = '' then '' else <br /> case when firstname is null then null else 'fname_' + convert(varchar, loanno) <br /> end <br /> end<br /><br />So if it's NULL, leave it as NULL. If it's '', leave it as it is but if it has a value, modify it.<br /><br />How will I use that kind of case in UPDATE SET?<br /><br />Thanks guys!<br /><br />Any help will be greatly appreciated!!! <img src='/community/emoticons/emotion-1.gif' alt=':)' /><br /><br />V1rt
  2. v1rtu0s1ty New Member

Share This Page