SunQuest
           MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old October 26th, 2003, 11:54 PM
cablehead cablehead is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 2 cablehead User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
bug with nested order bys

I am using a work around to achieve a Limit—with offset effect with sql server 7 taken from :

URL

Just quickly the following sql which works with mysql:

PHP Code:
 SELECT columns
FROM tablename
ORDER BY key ASC
LIMIT y
,


Can be achieved in mssql using:
PHP Code:
 SELECT FROM (
  
SELECT TOP x FROM (
    
SELECT TOP x FROM (
      
SELECT TOP (x+ycolumns
      FROM tablename
      ORDER BY key ASC
    
) AS foo ORDER BY key DESC -- ('foo' may be anything)
  ) AS 
bar                     -- ('bar' may be anything)
) AS 
baz ORDER BY key ASC      -- ('baz' may be anything


The strategy works well and is very fast - even when dealing with 200,000 plus records.

I've just hit a problem using mssql 7 when using the workaround. mssql seems to ignore the descending order by when ordering by more than two fields. That is; something like:

PHP Code:
 select top 45 *
from (
   
select top 45
       intPeopleID
,         
       
strFirstName,         
       
strLastName,
   
from tblOrgPeople
   order by          
       strFirstName ASC       
base 
order by      
    strFirstName  DESC 


produces the expected result. But with:

PHP Code:
 select top 45 *
from (
   
select top 45
       intPeopleID
,         
       
strFirstName,         
       
strLastName,
   
from tblOrgPeople
   order by          
       strFirstName
strLastName ASC       
base 
order by      
    strFirstName
strLastName  DESC 


the second descending order by is ignored. The result of the above query is sorted by firstname, lastname asscending.

Has anyone else come across this problem and know of a workaround or a patch to fix it?

Any help is greatly appreciated,
Andy.

Reply With Quote
  #2  
Old October 27th, 2003, 02:22 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 12 m 39 sec
Reputation Power: 37
No, you got it wrong. Desc/Asc is only applied to the preceeding column.

Code:
order by strFirstName desc, strLastName desc

Reply With Quote
  #3  
Old October 27th, 2003, 03:57 PM
cablehead cablehead is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 2 cablehead User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
heh - oops feeling silly now ..

Thank you! That's a life saver ..

Andy.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > bug with nested order bys


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway