Sunday, February 19, 2012

generate a sequential number

Hi,
I'm trying to generate a sequential number as part of a query I have.
I'm sorting the query using one of the items and need to generate a sequential number from 1 to N for the number of items in the selection.
I thought it sounds easy but could not figure this outHelp please

Thanks
MottyHi, I'm trying to generate a sequential number as part of a query I have. I'm sorting the query using one of the items and need to generate a sequential number from 1 to N for the number of items in the selection. I thought it sounds easy but could not figure this out
Q1 Help please
Thanks Motty

A1 As presented, this is a very general requirement however one approach to the issue (which may or may not be suitable depending on the detailed requirements), may be to insert the result set into a newly created #Temp table with an identity column seeded at 1.|||Same functionality with identity function and select into

select OrderId=identity(int,1,1),*
into #Table
from YourTable
order by ColumnX

No comments:

Post a Comment