HOW TO USE ROW_NUMBER IN SQLSERVER

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 640  View(s)
Ratings:
Rate this:
 I want to use ROW_NUMBER in sql server Please  help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to use ROW_NUMBER in sqlserver

    ROW_NUMBER is a function built-in to SQL Server that will return a row number for each record in your result set. You can further change resulting row number to reset the row number based on some value in the result set.

    PARTITION BY – If you supply this parameter, then the row number will reset based on the value changing in the columns supplied. This is kinda like using a GROUP BY.
    ORDER BY – This is the specified order of the row number that you would like. If you wanted the order of the row number to increment by an employee name (alphabetically), you do that here.

    
    

    select ROW_NUMBER() over (ORDER BY emp_name) AS RowNumber,Emp_ID,Emp_Name,Emp_Sal from Employee

    select ROW_NUMBER() over (PARTITION BY emp_sal ORDER BY emp_name) AS RowNumber,Emp_ID,Emp_Name,Emp_Sal from Employee

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!