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 |
|
jojo2006
Starting Member
5 Posts |
Posted - 2006-05-17 : 20:39:07
|
Hi...how can I write a dynamic sql statement to insert x number of child records? Thx in advance |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-05-17 : 20:45:43
|
| [code]insert into MyTable ( Col1,Col2,Col3)select Col1 = 'value1', Col2 = 'value2', Col3 = 'value3'union allselect Col1 = 'value4', Col2 = 'value5', Col3 = 'value6'union allselect Col1 = 'value7', Col2 = 'value8', Col3 = 'value9'union all...etc.[/code]CODO ERGO SUM |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-18 : 01:58:18
|
| or Use While loop to insert as many records as you want to insertMadhivananFailing to plan is Planning to fail |
 |
|
|
jojo2006
Starting Member
5 Posts |
Posted - 2006-05-18 : 13:53:14
|
| Could you show me how to write the while loop if the number of records is unknown?I'm unsure about how to create the parameter for the child data, too.Thanks again! |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-05-18 : 13:59:06
|
| >> number of records is unknown?U want to pass as a parameter the # of records to be inserted ?Also are u OK with same set of data or u want to have different data all the time ?If u need different data, u may need to write code (to generate data).Srinika |
 |
|
|
|
|
|