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
 create insert scripts from select

Author  Topic 

maevr
Posting Yak Master

169 Posts

Posted - 2009-11-06 : 08:00:00
I need to create multiple insert into scripts based on a select, how do i accomplish this?

One script per fnr.

example:
SELECT 'INSERT INTO ' + table1 + ' (fnr) ' +
'VALUES (' + fnr + ')' FROM table2

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-11-06 : 08:06:37
Are the tables and columns the variables? You will need to use dynamic sql to accomplish this.


Jim

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

maevr
Posting Yak Master

169 Posts

Posted - 2009-11-06 : 08:10:15
select distinct 'insert into table1(fnr) values (' + fnr + ');' from table2;

this seems to work, anyone sees any problem?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-06 : 09:29:27
If fnr is a character type then you have to add quotes around the value coming from column fnr but if fnr is numeric then it seems to be ok.


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

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-06 : 10:22:47
what is fnr

????

Fancy New Radical???

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-06 : 10:24:35
No - it is Rita's little brother


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

- Advertisement -