Click here to Skip to main content
15,887,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have problem with an SQL query. I want to select five records from a table and assign it 1 and the next 5 records assign it 2 and next 5 records assign it 3, etc...

How could I accomplish this.


Thanks.
Posted
Updated 25-Oct-11 0:58am
v2
Comments
Herman<T>.Instance 25-Oct-11 6:41am    
without any code it is hard to tell but I guess you need function to have a Row_Number?

1 solution

SQL
UPDATE Table SET record = ( (id-1)/5+1 )


Did you mean something like that?
It assigns [1,5] to 1, [6,10] to 2, etc.
 
Share this answer
 
Comments
Herman<T>.Instance 25-Oct-11 7:05am    
nice thinking
mohd vaquas 25-Oct-11 7:09am    
yes i need same as ...

how i can do like that can you please give me some more detail..
ShacharK 25-Oct-11 7:10am    
So did it work for you?
mohd vaquas 25-Oct-11 7:16am    
thanks for ur reply
update table set record=((id-1)/5+1

the above query what is the id?
can u please explain Little more

thanks
mohd vaquas 25-Oct-11 7:26am    
select ceiling(ROW_NUMBER() OVER (Order by TotalSale desc)) AS rownumber, * from #tempTable2

when i run this query its give me the sequential Rownumber like 1,2,3,4,5,6,7,8,9........
i need one more column which store the 1 for 1 to 5 record and 2 for 6 to 10 records and so on......

please help me how can i achieve this result
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900