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
 Transact-SQL (2000)
 Combine Columns

Author  Topic 

aberli
Starting Member

5 Posts

Posted - 2004-11-08 : 16:10:38
Hello everyone. I have a table with 4 columns: Domain, LANID, Employee and Facility. I need to combine Domain(US/) with LANID(KEAFB22), resulting in US\KEAFB22. I also need to combine Employee with Facility but will be able to figure that one out with your help on the first one. Thank you very much!

Thanks,
Aberli

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-11-08 : 16:27:03
SELECT Domain + '\' + LANID
FROM Table1

Tara
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-08 : 16:29:11
If the blighters allow NULLs then you might need to widen this to

SELECT COALESCE(Domain, '') + '\' + COALESCE(LANID, '')
FROM Table1

Kristen
Go to Top of Page

aberli
Starting Member

5 Posts

Posted - 2004-11-08 : 17:01:58
I'm hoping this will change the table before I export it to a .csv file. You're awesome!
Go to Top of Page

aberli
Starting Member

5 Posts

Posted - 2004-11-08 : 17:02:57
The "/" is already in Domain. So, will this change the table like I want it to? Thanks!

Thanks,
Aberli
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-11-08 : 17:07:40
SELECT COALESCE(Domain, '') + COALESCE(LANID, '')
FROM Table1

The query isn't going to change the table though. It just creates a result set containing how you want the data to look like. To update the table, you'll need to use UPDATE statement.

Tara
Go to Top of Page

aberli
Starting Member

5 Posts

Posted - 2004-11-08 : 17:15:12
Then I'll change the statement to: SELECT UPDATE(Domain, '') + UPDATE(LANID, '')???????????????????

Thanks,
Aberli
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-11-08 : 17:18:28
UPDATE Table1
SET WhateverColumnIsGettingThisChange = COALESCE(Domain, '') + COALESCE(LANID, '')

But please run this on a test system first to make sure you are getting the correct results.

Tara
Go to Top of Page

aberli
Starting Member

5 Posts

Posted - 2004-11-08 : 17:29:02
It worked! You are a true warrior and a princess. Thank you and thank you Kristen as well. Should you ever need help with WebTrends, let me know. Cheers from Chicago.

Thanks,
Aberli
Go to Top of Page
   

- Advertisement -