I liked AWithers' suggestion, so I tried it to see how it worked. Rather than delete my results, thought I would post it here in case it's of any value to you. Thanks, AW.
[tt]
Select TitleId, Title, Price From Books
TitleId Title Price
------------------------------ -------
1 Another Rainy Day 19.99
2 The Quick Brown Fox 21.00
3 Andy, Randy, and Kate 9.95
4 Skunk Anansie 100.00
5 To Kill A Mockingbird 5.98
6 Tribal Ancestors 17.50
7 Annual Anthems 11.25
(7 row(s) affected)
-- Create Tempory Table
CREATE TABLE #TEMPTABLE (
PkId int NOT NULL Identity,
SeqNo int NOT NULL,
Title varchar(40) NOT NULL,
Price decimal (5,2) NOT NULL,
Primary Key (PkId)
)
-- Fill temporary table
-- SeqNo is initially zero
Insert INTO #TEMPTABLE
Select 0, Title, Price
From Books Order by Price ASC
-- Now update SeqNo
declare @limit int
set @limit = 3 -- this will be 8 in your case
Update #TEMPTABLE
SET SeqNo =
(CASE when Pkid % @limit = 0
Then @limit
Else PkId % @limit END)
-- Report result and finish up
Select PkId, SeqNo, Price
From #TEMPTABLE -- see result below
drop table #TEMPTABLE
----------------------------
PkId SeqNo Price
----------- ----------- -------
1 1 100.00
2 2 21.00
3 3 19.99
4 1 17.50
5 2 11.25
6 3 9.95
7 1 5.98
(7 row(s) affected)
----------------------------
[/tt]