kSQL 

Selecting Odd or Even Rows with ABS() Function

Short little script that allows you to select Odd or Even rows from a table with an identity column:

IF OBJECT_ID('tempdb.dbo.#TestData','U'IS NOT NULL DROP TABLE #TestData; 

CREATE TABLE #TestData( ID INT IDENTITY(1,1) PRIMARY KEY NOT NULL, Glaven VARCHAR(100));

INSERT INTO #TestData(Glaven) 

SELECT NEWID() 

UNION 

SELECT NEWID() 

UNION 

SELECT NEWID() 

UNION 

SELECT NEWID() 

UNION 

SELECT NEWID();

SELECT ID, Glaven FROM #TestData WHERE ABS(ID) % 2 = 1 -- Select only Odds!

SELECT ID, Glaven FROM #TestData WHERE ABS(ID) % 2 = 0 -- Select only Evens!