Access ignores Order By in SQL Server queries

bruce_at_lmc

New member
Local time
Today, 13:32
Joined
May 14, 2009
Messages
4
Hi,

This makes no sense to me....

I have a SQL Server 9 (2008?) database in the cloud, and I've created an Access 2007 project (.adp). The connection works, I can see the tables and queries that I've created in SS, but when I double-click on a SS query in Access the data is correct but it isn't sorted like it should be.

When I run the same query in SS Mgmt Studio is sorts just fine.

What am I missing?

Thanks,
Bruce
 
Welcome to the site. Does the query have an ORDER BY clause?
 
Is the "query" you refer to actually a SQL view? Views are always unordered. ORDER BY is only valid in a view as part of a TOP query in which case the purpose of ORDER BY is purely to specify the selection criteria used by TOP, not to sort the results.

If you want sorted results then use a stored procedure instead of a view.
 
Yes, I use the TOP predicate. The query is below.

SELECT TOP (100) PERCENT HairID, HairDescription, HairShort, DisplayOrder
FROM bruce.Hair
ORDER BY DisplayOrder
 
maybe i have the answer

try this:

SELECT TOP(100) PERCENT WITH TIES HairID, HairDescription, HairShort, DisplayOrder
FROM bruce.Hair
ORDER BY DisplayOrder

that worked for me
 
Ah... Thanks for telling me this. In hind sight, this makes perfect sense.

Thanks for your time.

Bruce


Is the "query" you refer to actually a SQL view? Views are always unordered. ORDER BY is only valid in a view as part of a TOP query in which case the purpose of ORDER BY is purely to specify the selection criteria used by TOP, not to sort the results.

If you want sorted results then use a stored procedure instead of a view.
 

Users who are viewing this thread

Back
Top Bottom