Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Retrival of alternate rows using Query analyzer

Author  Topic 

anujrathi
Starting Member

9 Posts

Posted - 2006-06-18 : 15:03:11
Hi friends,

Using Query analyzer, How can I retrive alternate rows from any table, means I want to retireve even rows or odd rows only ?
Pls give me the query ?

Kristen
Test

22859 Posts

Posted - 2006-06-18 : 15:45:01
Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=67966
Go to Top of Page

sqldev80
Yak Posting Veteran

68 Posts

Posted - 2006-06-19 : 13:01:11
-----------FOR EVEN-------------

SELECT column_name FROM TABLE_NAME WHERE (column_name % 2) = 0


-----------FOR ODD-------------

SELECT column_name FROM TABLE_NAME WHERE (column_name % 2) <> 0
Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-20 : 00:16:09
Create table KK (Sq Int, Vr Varchar(10))
Declare @t int
Select @t =0
While @t <=1000
begin
Insert into kk Select @t ,Convert(varchar(10),'10'+@t)
Select @t = @t+1
End
Select * from KK
-- even
where convert(varbinary(1),right(SQ,1)) in (0x30,0x32,0x34,0x36,0x38)
-- odd
where convert(varbinary(1),right(SQ,1)) in (0x31),0x33,0x35,0x37,0x39)


OTHERWISE
-- eVEN
SELECT * FROM kk WHERE Sq LIKE '%[02468]'
-- ODD
SELECT * FROM kk WHERE SQ LIKE '%[13579]'

-- kk
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-20 : 02:52:56
quote:
Originally posted by sqldev80

-----------FOR EVEN-------------

SELECT column_name FROM TABLE_NAME WHERE (column_name % 2) = 0


-----------FOR ODD-------------

SELECT column_name FROM TABLE_NAME WHERE (column_name % 2) <> 0



Do you think this will work correctly?
What happens if the column is of varchar type?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-06-20 : 16:57:06
"Do you think this will work correctly?"

Madhi, give up!! - for folk that can't follow a "Duplicate link" link to co-ordinate answers under a single thread its better that their answers are quarantined!

Kristen
Go to Top of Page
   

- Advertisement -