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
 Please help me in Inserting

Author  Topic 

vedjha
Posting Yak Master

228 Posts

Posted - 2010-03-23 : 15:17:35
Hello Friends,

I have approax 45 rows insert into a new table

i have find rows from different table as

select c1,c2,c3 from table where condition
it gives me one row data.

i have find c4,c5 from CTE (Common table Expression)

it gives me 45 rows data

I have to mixup these output and insert in a new table

as :

insert into table2
(
c1,c2,c3,c4,c5
)
values
(
??
/* fetch those rows which we have discuss up side.
*/
)

please help me to insert. :)

Thank you

http://kiransoftech.com

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-23 : 16:06:58
one way:
declare @c1 int -- or whatever
declare @c2 int
declare @c3 int
select @c1=c1,@c2=c2,@c3=c3 from table where ...
insert table2
(
c1,c2,c3,c4,c5
)
SELECT
@c1,@c2,@c3,c4,c5 from (your select from CTE comes here and then you don't need a CTE) as dt


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -