This is a special keyword used for generate "Sequential No' on a row within result set. Sequential no start from 1 for first row, second row no is 2 in each partition. Usually used in Select Statement.
ROW_NUMBER () OVER ( [ <partition_by_clause> ] <order_by_clause> )
Arguments:
ROW_NUMBER has Two Arguments are
1. Partition_by_clause and
2. order_by_clause
ROW_NUMBER() with PARTITION :
Partition BY Clause to generate Sequence No to separate of query result and Order By works on over clause for order the results.
SELECT ROW_NUMBER() OVER(PARTITION BY IsApproved ORDER BY Id DESC ) AS SL_NO ,[Name]
,[Address] ,[Telephone] ,[IsApproved]
FROM [RemitERP].[dbo].[Agm_Agent]
WHERE IsApproved IS NOT NULL
SELECT
ROW_NUMBER() OVER( ORDER BY Id DESC ) AS SL_NO ,[Name]
,[Address] ,[Telephone] ,[IsApproved]
FROM [Agm_Agent]
WHERE IsApproved IS NOT NULL
,[Address] ,[Telephone] ,[IsApproved]
FROM [RemitERP].[dbo].[Agm_Agent]
WHERE IsApproved IS NOT NULL
ROW_NUMBER() Only ORDER BY :
Order by clause works all result of the query and generate sequence No.
SELECT
ROW_NUMBER() OVER( ORDER BY Id DESC ) AS SL_NO ,[Name]
,[Address] ,[Telephone] ,[IsApproved]
FROM [Agm_Agent]
WHERE IsApproved IS NOT NULL
Comments
Post a Comment