|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Selecting the Top Nth Record and the Value of N increments by 1 EverytimeI 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 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 |
|||||||||||||||||||||||