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)
 Adding data from 1 column into another

Author  Topic 

Starsky51
Starting Member

2 Posts

Posted - 2010-09-29 : 07:26:49
HI all,
I have a bd that has 10 columns named user1,user2 etc and 10 columns named dispo1, dispo2 etc and I want to just join all the users together in 1 column and all the dispo in another column. Can anybody help me with this?

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-09-29 : 12:03:24
Select user1 + ',' + User2 -- and so on
as UserColumn,
dispo1 + ',' + dispo2 -- and so on
as DispColumn
From YourTable


If any column is nullable make sure to use IsNull

Ex:
Select Isnull(user1 + ',','') + User2 --Assuming that User1 is nullable and User2 is not null column.
Go to Top of Page

da42
Starting Member

3 Posts

Posted - 2010-09-29 : 12:29:42
Also, if any of your fields are integer/float/etc, you might get an error trying to mathematically ADD+ a ',' comma to it, so you might need to do a convert to nvarchar or some other type before concatenating. Have seen that before.
Go to Top of Page
   

- Advertisement -