SQL Query to display Odd and Even rows

Manojjupally
Posted by Manojjupally under Sql Server category on | Points: 40 | Views : 2475
Query to display odd rows and even rows


odd :

select * from( 
SELECT id,name, ROW_NUMBER() OVER(ORDER BY id DESC) AS 'RowNumber',
FROM emp
) oddtable where (RowNumber % 2) = 1


even :


select * from( 
SELECT id,name, ROW_NUMBER() OVER(ORDER BY id DESC) AS 'RowNumber',
FROM emp
) eventable where (RowNumber % 2) = 0

Comments or Responses

Login to post response