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 2000 Forums
 SQL Server Development (2000)
 Insert Same Record 'X' amount of times

Author  Topic 

JezEling
Starting Member

4 Posts

Posted - 2007-07-24 : 09:46:49
Hi All,

I have a sql statement which is driving me around the twist. I have a table of data made up of individual part numbers which I need to compile and build into a new table. I need to insert the part numbers into a new table once for each week of the year, so each part number will be in the table 52 times, additionally I need to store the week number in the same record.

Try as I might I can't figure out which way to achive this, some sort of loop would be the most obvious choice but is not something i've done before in SQL.

Any pointers or suggestions would be very much appreciated.

Cheers

Jez

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 09:48:11
make use of F_TABLE_NUMBER_RANGE from here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47685&SearchTerms=F_TABLE_NUMBER_RANGE


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

Go to Top of Page

JezEling
Starting Member

4 Posts

Posted - 2007-07-24 : 10:19:29
Thanks for that and the quick response. However i'm unsure as to how to link this up to create my new table structure, i.e. the same part number entered 52 times for all 1188 part numbers stored in my inital table.

Not wishing to sound dumb here, but any other pointers would be much appreciated.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 10:22:40
[code]
insert into yourtable( . . . )
select < column list from your_initial_table >
from your_initial_table cross join F_TABLE_NUMBER_RANGE(1, 52)
[/code]


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

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-24 : 11:21:43
or if you're doing it from SSMS you can do:

Insert into....
select ....

GO 52

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -