SQL Server 2005 SP3 Order by

Hey Guys,

Using server 2003 and sql 2005 sp3.
MS Link I found:http://support.microsoft.com/kb/926292

"      The SELECT statement uses the TOP (100) PERCENT expression.
"      The SELECT statement uses the ORDER BY clause.

When you query through the view, the result is returned in random order.

But for some reason the patch is not fixing the problem.
Please guide.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
for on the safer side, you need to put the ORDER BY when calling the View

SELECT * from yourView order by Column1
ShivtekAuthor Commented:
I am not the programmer, just getting a possible solution for a programmer. Can you please elaborate a bit more.

Use this workaround:
select top 99 percent * from yourview order by column1
Check this link for details:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.


sorry I mean
create view yourview as
select top 99 percent * from yourtable order by column
Check the link I've mentioned for details.
Anthony PerkinsCommented:
You should never have an ORDER BY clause in a VIEW as it is a very bad idea.

But to answer your specific question, what you have discovered is the fact that MS finally (with MS SQL Server 2005) fixed the problem where developers were using the kluge SELECT 100 PERCENT ... ORDER BY.

You can continue looking for cheesy workarounds such as using SELECT TOP 99.99999 PERCENT .... ORDER BY or make sure the problem is fixed correctly as Aneesh has suggested.  In other words, remove the TOP 100 PERCENT and ORDER BY clause and apply the ORDER BY to the VIEW.
I would tend to agree with acperkins, Honestly I've never used order by inside a view because it's a bad practice. but I was just showing the workaround. Whether you want to call it cheesy or not, it's up to you. LOL
And actually because of the asker posting I've become aware that SP3 fixed that problem. :)
ShivtekAuthor Commented:
This used to work fine when I was using SQL 2000.

Not sure why wont work with SQL 2005.
Anthony PerkinsCommented:
>>Not sure why wont work with SQL 2005.<<
Trust me there were many kludges like this fixed in SQL Server 2005.  So perhaps it is time that you start doing it right, rather than wait for the next version to break your code all over again.
Anthony PerkinsCommented:
>>This used to work fine when I was using SQL 2000.<<
Alternatively, you can stick with SQL Server 2000, just understand that support for this version has now expired.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.