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 2000 Forums
 SQL Server Development (2000)
 Join two columns data to populate another column

Author  Topic 

webfort
Starting Member

9 Posts

Posted - 2006-11-06 : 07:45:13
Hi,

Was wondering if any one could help me, I'm looking to get the date from two columns in a database and insert them in to one column, its basically the first and second name with a "." in the middle and the domain address to follow.

Is this possible?

Thanks

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-11-06 : 07:49:53
Insert Table
Select FirstName + '.' + SecondName + DoMainaddress From TableName

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-06 : 08:52:26
Or just to be safe for NULLS...

Insert Table
Select ISNULL(FirstName + CASE WHEN SecondName IS NULL THEN '@' ELSE '.' END, '') + ISNULL(SecondName + '@', '') + ISNULL(DoMainaddress, '') From TableName


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

webfort
Starting Member

9 Posts

Posted - 2006-11-06 : 09:05:33
Hi, thanks for that, is there anyway to get it to insert it in to the corrosponding record?

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-06 : 09:09:47
I don't understand you. What do you mean with "is there a way to insert it into the corresponding record"?
Do you mean you would like to UPDATE some record with the combined value as posted above?

UPDATE mt
SET mt.MyColumn = ISNULL(FirstName + CASE WHEN SecondName IS NULL THEN '@' ELSE '.' END, '') + ISNULL(SecondName + '@', '') + ISNULL(DoMainaddress, '')
FROM MyTable mt
INNER JOIN OtherTable ot ON ot.pk = mt.pk



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-06 : 09:16:29
How about creating computed column?

Alter Table xyz
(
Add SomeCol as (SNULL(FirstName + CASE WHEN SecondName IS NULL THEN '@' ELSE '.' END, '') +
ISNULL(SecondName + '@', '') + ISNULL(DoMainaddress, ''))
)



Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

webfort
Starting Member

9 Posts

Posted - 2006-11-06 : 09:19:54
Hi,

the post that chiragkhabaria posted works, but when I it inserts it does not insert the record to the correct record, it inserts it at the bottom of the table. So row 1 has for name bob and surname smith, it does not insert the email in the same row

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-06 : 09:23:10
Of course not. Read my previous answer about UPDATE!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -