Home All Groups Group Topic Archive Search About

Selecting the Top Nth Record and the Value of N increments by 1 Everytime

Author
3 Aug 2006 5:59 PM
rishabhshrivastava
Hi All,
I want to Select the MAX of TOP Nth Record and this Value of N should
be incremented by 1, I am using WHILE LOOP but getting an error Please
let me know what am I doing wrong..

I am doing this because I am inserting the Values in another table
after I find the MAX Nth
Record...


declare @groupNumber as int
declare @counter as int

SET @counter = 0

WHILE @counter < 100

BEGIN

SET @counter = @counter + 1

SET @groupNumber = Select MAX(groupNumber) from table where groupNumber

IN(Select TOP cast(@counter as
varchar) groupNumber from table)

INSERT INTO table2 (groupNumber) VALUES (@groupNumber)

END

Author
3 Aug 2006 10:21 PM
Anith Sen
Please post your table DDLs, sample data & expected results for others to
better understand your requirements. For details, refer to:
www.aspfaq.com/5006

--
Anith

AddThis Social Bookmark Button