Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


how to write the query to select the rows are in the order
of either 1,3,5,7... or 2,4,6,8,...

Answers were Sorted based on User's Feedback



how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / senthil

select * from dbo.outs_OpenItems where OIR_ID % 2=1

Is This Answer Correct ?    20 Yes 9 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / vijay sultampur

For 1,3,5,7...

select * from emp where (rowid,1) in (select rowid,mod
(rownum,2) from emp);

For 2,4,6,8,...

select * from emp where (rowid,0) in (select rowid,mod
(rownum,2) from emp);

Is This Answer Correct ?    7 Yes 0 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / rajesh verma

1> incase of 2,4,6,8,...

select col1,col2 from tab1 where col1 in
(Select case when Row_number() over (order by col1)%2=0
then col1 else 0 end from tab1)

2> in case of 1,3,5,7,....

select col1,col2 from tab1 where col1 in
(Select case when Row_number() over (order by col1)%2=1
then col1 else 0 end from tab1)

Is This Answer Correct ?    6 Yes 1 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / leo

with contactinfo as (
select contactid,firstname,row_number() over (order by
firstname)as row from person.contact
)
--select * from contactinfo where row % 2 =0

Is This Answer Correct ?    4 Yes 1 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / md. niyaz

For: 2, 4, 6, ......

select * from <Table_Name> where <Column_Name> % 2 = 0

==============Niyaz====================================

For: 1, 3, 5, ......

select * from <Table_Name> where <Column_Name> % 2 = 1

Is This Answer Correct ?    3 Yes 1 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / vijayplsql@gmail.com

For 1,3,5,7...

select * from emp where (rowid,1) in (select rowid,mod
(rownum,2) from emp);

For 2,4,6,8,...

select * from emp where (rowid,0) in (select rowid,mod
(rownum,2) from emp);

Is This Answer Correct ?    1 Yes 0 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / tiru

select * from
(select emp.ename, emp.age, (rownum+1) AS XX from employee
emp )
where remainder(XX,2) = 0;

select * from
(select emp.ename, emp.age, (rownum+1) AS XX from employee
emp )
where remainder(XX,2) = 1;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

Your company has 50 branches all over the country all the branches, including the head office have sql server as the database every night all 50 branches upload certain information to the head office which replication topology is best suited for the above scenario?

0 Answers  


what is the diffrence between Snap Shot and Transaction Replication

2 Answers   CSC,


How do I clean up sql server transaction log?

0 Answers  


How to drop existing views from a database in ms sql server?

0 Answers  


Is it possible to import data directly from t-sql commands without using sql server integration services? If so, what are the commands?

0 Answers  


What are the types of lock supported by ?

0 Answers   HCL,


What should we do to copy the tables, schema and views from one SQL Server to another?

3 Answers  


What is enhanced database mirroring in sql server 2008?

0 Answers  


How to a Query to copy data from on table to another table.

6 Answers   Cap Gemini,


select top 5 * from emp order by newid() my question is , how this query get executed?

5 Answers  


Write an sql query to find first weekday of the month?

0 Answers  


what is memory-optimized nonclustered indexes

0 Answers  


Categories