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.
| 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 |
 |
|
|
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 |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-06-20 : 00:16:09
|
| Create table KK (Sq Int, Vr Varchar(10))Declare @t intSelect @t =0While @t <=1000 begin Insert into kk Select @t ,Convert(varchar(10),'10'+@t) Select @t = @t+1 EndSelect * from KK-- evenwhere convert(varbinary(1),right(SQ,1)) in (0x30,0x32,0x34,0x36,0x38)-- oddwhere convert(varbinary(1),right(SQ,1)) in (0x31),0x33,0x35,0x37,0x39)OTHERWISE-- eVENSELECT * FROM kk WHERE Sq LIKE '%[02468]' -- ODDSELECT * FROM kk WHERE SQ LIKE '%[13579]'-- kk |
 |
|
|
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?MadhivananFailing to plan is Planning to fail |
 |
|
|
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 |
 |
|
|
|
|
|
|
|