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-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
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
0 comments:
Post a Comment