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

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

im1dermike
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?

Thanks!

tkizer
Almighty SQL Goddess

USA
36601 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.

SELECT ...
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
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

im1dermike
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  
 New 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.14 seconds. Powered By: Snitz Forums 2000