Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

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.

0
Shivtek
Asked:
Shivtek
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
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
0
 
ShivtekAuthor Commented:
I am not the programmer, just getting a possible solution for a programmer. Can you please elaborate a bit more.

Thanks
0
 
ralmadaCommented:
Use this workaround:
select top 99 percent * from yourview order by column1
Check this link for details:
http://sqlservernation.com/blogs/brandongalderisi/archive/2009/03/15/when-ordering-in-a-view-doesn-t-work.aspx 
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ralmadaCommented:

sorry I mean
create view yourview as
select top 99 percent * from yourtable order by column
 
Check the link I've mentioned for details.
0
 
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.
0
 
ralmadaCommented:
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. :)
0
 
ShivtekAuthor Commented:
This used to work fine when I was using SQL 2000.

Not sure why wont work with SQL 2005.
0
 
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.
0
 
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now