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
 General SQL Server Forums
 New to SQL Server Programming
 Copy one column1 Table A, to column2 Table B

Author  Topic 

reading2009
Starting Member

22 Posts

Posted - 2009-12-29 : 14:22:33
Hi,

I am looking for copy data from one column from one table(1st) to another column in the 2nd table.

But I want the out in the 2nd table in a particular way.

ColumnA in 1st table
abc
def
ghi
dgy

Desired output in 2nd table
ColumnB
abc,def,ghi,dgy

I tried
INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Contact

but i get the output same as 1st table.

Any help here....

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-12-29 : 14:29:54
Can you provide some more information..table structures??

So you have a single column (probably FullName) in table 2 and you want to insert the value "FirstName,LastName" from table 1 into this new column in table2?

Go to Top of Page

reading2009
Starting Member

22 Posts

Posted - 2009-12-29 : 14:42:33
Yes, you are right. I want different rows in coulmn a in 1st table to appear in 1 row, comma seperated values in column b of second table.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-12-29 : 15:06:17
Have a look at this topic to see how to concatenate without a UDF.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254
Go to Top of Page

reading2009
Starting Member

22 Posts

Posted - 2009-12-30 : 09:42:04
Thank you. I will go through your material today and give it a try.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-12-30 : 10:01:30
You're welcome. Post back if you face any difficulties (along with sample data this time ).
Go to Top of Page
   

- Advertisement -