I have a table full of documents with serial numbers – columns:
- docid int
- writing text
- submissionDate datetime
…and I’d like to find out where a particular serial number lies in a query against the table.
For example, if I ordered the resultset by submissionDate asc, I might want to know where document 34 is within that ordering (i.e. is it in position 11?)
How do I do this?
It looks like you’re trying to get the row number even if that’s not one of the rows being returned. You can use a CTE for that:
This also requires SQL Server 2005 or greater of course.