Improve your skills

August 12, 2016

Add Row Number in SQL Select Query Without Using ROW_NUMBER()


This article explain, how we can add sequence row number to a SQL select query starting from 1 onward without using ROW_NUMBER(). 

Following example describe all process step by step in easy way.

Example-

First of all we create a test table and assign some dummy data (Here my table name is 'tblStudent') as below-
how-to-add-row-number-without-using-row-number-function-in-sql-server











Write and run following query in SQL Query window.

-- insert data into a temp table '#tempTbl' with a new identity(1,1) column
SELECT IDENTITY(INT,1,1) AS row_num, name 
INTO #tempTbl FROM tblStudent

-- select all data from temp table
SELECT * FROM #tempTbl

-- drop temp table after getting final result
DROP TABLE #tempTbl


Result:
how-to-set-row-number-in-select-query-in-sql-server














0 comments:

Post a Comment

Subscribe for Latest Update

Popular Posts