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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Update fullname Column

Author  Topic 

Harvey85
Starting Member

4 Posts

Posted - 2011-09-07 : 15:03:29
Hi
I want to update my taget fullname column which is
fullname= lastname+''+firstname+''+midlename

Input(source) fullname comes in

sysid lastname firstname middlename
1 carter john null

2 null irene null


as fullname for sysid is already present in target fullname as

1. goshi cliff charles

2. rubella derrick iyen

therefore , i want to update only the field which comes in as not null


expected result:
1. carter john charles

2. rubella irene iyen


my 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.sysID
WHERE
A.lastname IS NOT NULL OR
A.firstname IS NOT NULL OR
A.A.middlename IS NOT NULL

Plz suggest me , how to do it
I 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 Optimizer
TG
Go to Top of Page
   

- Advertisement -