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)
 insert multiple fields from a table to a ...

Author  Topic 

PGG_CA
Starting Member

24 Posts

Posted - 2012-06-20 : 13:04:05
... single field in another table.

I need to copy the data from multiple fields in a table and put everything into a single field in another table.

For example:
Table1
fields:f1 f2 f3 f4 f5
data: True 123 this is the problem. called support 25.15

After the query,
Table2
field: col1
data: True, 123, this is the problem., called support, 25.15


How do I best accomplish this? Thanks for any help.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-20 : 13:13:57
INSERT INTO Table2
SELECT f1+ ',' + f2 + ',' + f3 + ',' + f4 + ',' +f5
FROM table1

Jim


Everyday I learn something that somebody else already knew
Go to Top of Page

Gigabyte
Starting Member

30 Posts

Posted - 2012-06-20 : 13:51:15
SELECT * INTO <DESTINATION_TABLE> FROM <SOURCE_TABLE>

NOTE: DESTINATION_TABLE WILL AUTOMATICALLY BE CREATED WHEN YOU EXECUTE ABOVE QUERY. PLEASE GIVE A NEW NAME FOR DESTINATION TABLE WHICH IS NOT IN THE DB.

GIGABYTE+
Go to Top of Page

PGG_CA
Starting Member

24 Posts

Posted - 2012-06-20 : 16:00:48
I tried using the + in my select statment, but I get the error " The data types varchar and text are incompatible in the add operator".
Go to Top of Page

PGG_CA
Starting Member

24 Posts

Posted - 2012-06-20 : 16:07:12
Fixed it. I used the convert function to 'convert' text to varchar.
Go to Top of Page

Gigabyte
Starting Member

30 Posts

Posted - 2012-06-21 : 08:24:51
If you are concatenating, I believe you need to use cast or convert . .

If you provide the query you are using, we could modify it.

GIGABYTE+
Go to Top of Page
   

- Advertisement -