Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Harvey85
Starting Member
4 Posts |
Posted - 2011-09-07 : 15:03:29
|
| Hi I want to update my taget fullname column which isfullname= lastname+''+firstname+''+midlenameInput(source) fullname comes in sysid lastname firstname middlename 1 carter john null 2 null irene nullas fullname for sysid is already present in target fullname as 1. goshi cliff charles2. rubella derrick iyentherefore , i want to update only the field which comes in as not nullexpected result:1. carter john charles2. rubella irene iyenmy query is;UPDATE A SET fullname= RTRIM(LTRIM(A.lastname))+', '+RTRIM(LTRIM(A.firstname))+' '+RTRIM(LTRIM(A.middlename)) FROM B INNER JOIN ON A.sysID=B.sysIDWHEREA.lastname IS NOT NULL OR A.firstname IS NOT NULL ORA.A.middlename IS NOT NULLPlz suggest me , how to do itI really appreacite your help |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2011-09-07 : 17:35:45
|
Because you have all the individual components already in the database (which is good) you should not also store the "display" version of the concatenated parts. Leave that work for the frontend. If you want/need to be able to return the display value from the database then use a function rather than storing it.But, for your function, use ISNULL. Something like this:isNull(A.lastname + ', ','') + isNull(A.firstname + ' ','') + A.middlename Be One with the OptimizerTG |
 |
|
|
|
|
|