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 2005 Forums
 Transact-SQL (2005)
 Select even number records from a table

Author  Topic 

gsvnreddy
Starting Member

3 Posts

Posted - 2007-06-13 : 05:13:44
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
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-13 : 05:19:43
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

30421 Posts

Posted - 2007-06-13 : 06:28:13
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

30421 Posts

Posted - 2007-06-13 : 06:29:05
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)

7020 Posts

Posted - 2007-06-13 : 07:15:03
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
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-13 : 08:43:00
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

22864 Posts

Posted - 2007-06-13 : 09:03:47
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
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-13 : 09:06:38
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)

7020 Posts

Posted - 2007-06-13 : 09:22:32
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
   

- Advertisement -