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.
| 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.JimEveryday I learn something that somebody else already knew |
 |
|
|
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? |
 |
|
|
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. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
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. |
 |
|
|
|
|
|