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)
 Loop

Author  Topic 

oahu9872
Posting Yak Master

112 Posts

Posted - 2007-03-14 : 21:07:27
I have a column with 20 possible values. I want to run a query that will pull 15 rows for each possibility, for a total of 300 rows. Is there a way to set up a loop to find a value, pull it 15 times, then go onto the next value?


Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-15 : 01:35:35
select x.col1, y.number
from (select distinct col1 from table1) as x
cross join (select number from master..spt_values where name is null and number between 1 and 15) as y
order by x.col1, y.number


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -