SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select even number records from a table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gsvnreddy
Starting Member

India
3 Posts

Posted - 06/13/2007 :  05:13:44  Show Profile  Reply with Quote
How to display even number records from a table.

Example: Suppose there is a table Temp, this table contains one column names. Suppose this table contains data like this,

names

Jacob
Nutan
Newton
Franco
Ramco
Lanco

etc, from this Temp table how to select even number records, which are Nutan,Franco,Lanco etc.

Please help me.

harsh_athalye
Flowing Fount of Yak Knowledge

India
5581 Posts

Posted - 06/13/2007 :  05:19:43  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
For determining even/odd records, it is must to assign row numbers and for generating row number, it is necessary to decide order of the records. So which field decides order of values? Clearly it is not alphabetic order.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 06/13/2007 :  06:28:13  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Add an identity column to your temp table and then

select * from #temptable where identcol % 2 = 0


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 06/13/2007 :  06:29:05  Show Profile  Visit SwePeso's Homepage  Reply with Quote
But you better post you full problem here roght away.
I have a suspicion that you will post next related problem here within hours...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 06/13/2007 :  07:15:03  Show Profile  Reply with Quote
There are plenty of solutions to your problem on this thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=63512



CODO ERGO SUM
Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5581 Posts

Posted - 06/13/2007 :  08:43:00  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
None of the solutions in that thread is helpful unless you have an identity column.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 06/13/2007 :  09:03:47  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by harsh_athalye

None of the solutions in that thread is helpful unless you have an identity column.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"


May be NTILE Function will help

Madhivanan

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

harsh_athalye
Flowing Fount of Yak Knowledge

India
5581 Posts

Posted - 06/13/2007 :  09:06:38  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
quote:
Originally posted by madhivanan

quote:
Originally posted by harsh_athalye

None of the solutions in that thread is helpful unless you have an identity column.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"


May be NTILE Function will help

Madhivanan

Failing to plan is Planning to fail



Not unless there is an ORDER BY clause, which is what my original question is.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 06/13/2007 :  09:22:32  Show Profile  Reply with Quote
quote:
Originally posted by harsh_athalye

None of the solutions in that thread is helpful unless you have an identity column.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



I doubt that any of the solutions on that thread could be called "helpful", with or without an identity column.



CODO ERGO SUM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000