TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
SQL Query To Get The Row Number
Arun Kumar
Jul 26
2016
Code
657
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
-- Using Row_Number
SELECT
ROW_NUMBER() OVER(
ORDER
BY
UserName
DESC
)
AS
Row
,UserName
,LoweredUserName
--,ROUND(SalesYTD,2,1) AS "Sales YTD"
FROM
aspnet_Users
WHERE
IsAnonymous
IS
NOT
NULL
-- Using CTE
WITH
ServiceOrders
AS
(
SELECT
ROW_NUMBER() OVER (
ORDER
BY
CreatedOn)
AS
RowNumber
,ServiceOrderID
,DueDate
FROM
ServiceOrder
)
SELECT
ServiceOrderID, DueDate, RowNumber
FROM
ServiceOrders
WHERE
RowNumber
BETWEEN
10
AND
20;
-- Using Partition
SELECT
ROW_NUMBER() OVER(PARTITION
BY
SvcReqID
ORDER
BY
ServiceTypeDesc
DESC
)
AS
Row
,ServiceOrderID
,DueDate
,SvcReqID
FROM
ServiceOrder
WHERE
SvcReqCancellationTypeID
IS
NOT
NULL
ORDER
BY
ServiceTypeDesc
SQL Query