 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 27th, 2006, 09:54 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Alternate Rows with no primary key
Hi All!
Is there any way to retrieve alternate rows from single query,without using any cursor or temptable .
There is rownum,rowid in Oracle,is there any equivalent in SQL Server 2000??
Thanks in Advance.
Cheers :)
vinod
__________________
Cheers :)
vinod
|
|

March 27th, 2006, 08:02 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
|
|
No, not in SQL 2000, not without a temp table, cursor, or table variable, unless the underlying result set already has some sort of integer identity, in which case you could approximate it.
In SQL 2005 you could by using the Row_Number() function.
For examples see
http://www.mutuallybeneficial.com/in...umber_2005.htm
David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
|
|

March 29th, 2006, 02:39 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
I'm curious about your request. What would be the purpose of selecting alternate rows? What kind of result set would you be looking for?
Thanks,
Richard
|
|

March 30th, 2006, 09:31 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hii rstelma!!
Its a very nice link provided by you ,thanks Again !!
Its a legacy System which has data from two different soureces.
for every insert operation from SourceA , SourceB insert a row with some values.
The problem is that there is no unique/primary key in the table.But the Client ensures that first row is from source A, 2nd From Source B and so on.
Well its also an interview question i found for DBA !! :)
Cheers :)
vinod
|
|

March 30th, 2006, 12:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Seems like you could add a bit column called [Sourc] and use the modulus function to turn the bit on from source A and off for source B. Then future queries would be direct based on the bit. Since there's no primary key you could add that column first then:
Update [table] set Source = 1 where [primary key] % 2 = 0
|
|

March 31st, 2006, 01:51 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
You can't rely on the physical order of the table if there is a clustered index on it.
|
|

March 31st, 2006, 03:58 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hii rstelma!!
We have no control over table(structure-add column)modifications,we can only query the table.
well we sort out using cursors and temp table.
Thanks again rstelma.
Cheers :)
vinod
|
|

March 31st, 2006, 12:00 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Looks like you'll have to do it in your application.
|
|

April 5th, 2006, 06:10 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am not sure I understand your question. If you want to retireve every other row can't you simply select where your rowid is either odd or even?? Simple logic to build.
|
|
 |