Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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
 
Old March 27th, 2006, 09:54 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default 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
 
Old March 27th, 2006, 08:02 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old March 29th, 2006, 02:39 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

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

 
Old March 30th, 2006, 09:31 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

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
 
Old March 30th, 2006, 12:24 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

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

 
Old March 31st, 2006, 01:51 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You can't rely on the physical order of the table if there is a clustered index on it.

 
Old March 31st, 2006, 03:58 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

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
 
Old March 31st, 2006, 12:00 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Looks like you'll have to do it in your application.

 
Old April 5th, 2006, 06:10 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Primary key cf2006 BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 July 31st, 2006 07:21 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.