display row number in sql code example
Example 1: sql row number
SELECT
ROW_NUMBER() OVER(PARTITION BY recovery_model_desc ORDER BY name ASC)
AS Row
name, recovery_model_desc
FROM sys.databases WHERE database_id < 5;
Example 2: create row number in sql
SELECT t.A, t.B, t.C, ROW_NUMBER() OVER (ORDER BY t.A) as newId
FROM dbo.tableZ AS t
ORDER BY t.A;
Example 3: how to use row number function in sql server
SELECT ROW_NUMBER() OVER(ORDER BY SUM(SalesAmountQuota) DESC)
AS RowNumber,
FirstName, LastName,
CONVERT(varchar(13), SUM(SalesAmountQuota),1) AS SalesQuota
FROM dbo.DimEmployee AS e
INNER JOIN dbo.FactSalesQuota AS sq
ON e.EmployeeKey = sq.EmployeeKey
WHERE e.SalesPersonFlag = 1
GROUP BY LastName, FirstName;