Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I am using SQL to generate Serial number in SQL server 2008
SELECT ROW_NUMBER() OVER ( ORDER BY Column ) AS SrNo
Above SQL will generate SrNo in the ascending order
1 2 3 4 5
but I want to generate it in descending order.
5 4 3 2 1
You need to sort the ORDER BY column DESC
SELECT SrNo FROM (SELECT ROW_NUMBER() OVER (ORDER BY YOUR_COLUMN ) AS SrNo FROM YOUR_TABLE) X ORDER BY SrNo DESC
Add a comment
select * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS SNO, ColumnName FROM table )r ORDER BY SNO Desc
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.