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)
 Insert into table using select

Author  Topic 

nvakeel
Yak Posting Veteran

52 Posts

Posted - 2008-01-31 : 22:39:19
I have a table which has 3 col's. (table a ->col1,col2,col3)
now i have
Insert into table b
select col1 where col3 = x
Insert into tableb
select col2 where col3 = y

Now i have to join these two insert commands to one like
Insert into table b
select ****************???

can you help me.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-31 : 22:48:33
Insert into table b
select col1 where col3 = x
union all
select col2 where col3 = y

Also you need to make sure col1 & col2 are of same datatype as the field into which you are inserting
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-02-01 : 03:06:01
[code]Insert into table b
select col1 from tablea where col3 = x
union all
select col2 from tablea where col3 = y[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

nvakeel
Yak Posting Veteran

52 Posts

Posted - 2008-02-01 : 15:49:06
thnkss
Go to Top of Page
   

- Advertisement -