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 2005 Forums
 Transact-SQL (2005)
 Query help!

Author  Topic 

frank.svs
Constraint Violating Yak Guru

368 Posts

Posted - 2008-08-21 : 03:15:11
Dear Pals ,

I have a small requirement, I have two tables "test" and "trg"


drop table test
create table test
( col1 varchar(10),
col2 varchar(10),
col3 varchar(10),
col4 varchar(10)
)

insert into test
select 'a','b','c','d'
union all
select 'e','f','g','h'

select * from test


-- Output
/*

col1 col2 col3 col4
a b c d
e f g h

*/


I have one more table

create table trg
(id int identity(1,1),
col varchar(10)
)

I need to data to be loaded into "trg" table as below

select * from trg

id col
-------
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h

Can anyone help me out?

Thanks in Advance.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-21 : 03:45:38
insert into trg(col)
select col1 from test
union all
select col2 from test
union all
select col3 from test
union all
select col4 from test


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

frank.svs
Constraint Violating Yak Guru

368 Posts

Posted - 2008-08-21 : 04:45:35
Thank You!
Go to Top of Page
   

- Advertisement -