Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 ORDER BY - Very quick question
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

222 Posts

Posted - 05/16/2008 :  15:57:55  Show Profile  Reply with Quote
I have a view that I want to display in a particular order so I added "ORDER BY <column> DESC" to the end of my view logic. When I run it as a query or even when I execute the view in the modify window, it appears correctly ordered. But, when I just "Open View", it's not ordered how I want it. I don't know why it doesn't order it when you open the view, but how can I resolve this issue?


Almighty SQL Goddess

38200 Posts

Posted - 05/16/2008 :  16:04:13  Show Profile  Visit tkizer's Homepage  Reply with Quote
Because you aren't guaranteed order unless ORDER BY is in your SELECT. It doesn't matter if the ORDER BY is in your view.

FROM YourView
ORDER BY YourColumn

YourView could have an ORDER BY, but it doesn't matter. What matters is the SELECT query calling the view.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server

Database maintenance routines:
Go to Top of Page

Posting Yak Master

222 Posts

Posted - 05/16/2008 :  16:43:11  Show Profile  Reply with Quote
I see.

I'm populating data in an Excel worksheet and I want it to be in a particular order. My SELECT statement pulls data from my view for an OPENROWSET call. I've altered the statement, adding the bold code below per your suggestion, but it still isn't coming out in any sort of order when I open the Excel file.

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\TEMP.xls;','SELECT * FROM [WSC 2nd day App$]') select * from SQL_TEMP1 order by [Days Referral Open] DESC

What gives?
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000