[dba-SQLServer] Views don't sort

David McAfee davidmcafee at gmail.com
Fri May 20 18:10:37 CDT 2011


Can't you just call it from a SPROC and use a pass through query to call
that?

CREATE PROCEDURE stpSomeSproc AS
SELECT * FROM vwMyView ORDER BY colMyCol



On Fri, May 20, 2011 at 4:00 PM, jwcolby <jwcolby at colbyconsulting.com>wrote:

> I understand that.  Unfortunately to do it "the safe way" means that it has
> to be done by the Jet engine on the workstation.  That means back to all of
> the index pulls etc.
>
>
> John W. Colby
> www.ColbyConsulting.com
>
> On 5/20/2011 4:47 PM, Stuart McLachlan wrote:
>
>> Be careful with that. It is not guaranteed to work!
>>
>> See http://msdn.microsoft.com/en-us/library/ms188385.aspx
>> <quote>
>> The ORDER BY clause is not valid in views, inline functions, derived
>> tables, and subqueries,
>> unless TOP is also specified.
>> ...
>> When ORDER BY is used in the definition of a view, inline function,
>> derived table, or
>> subquery, the clause is used only to determine the rows returned by the
>> TOP clause. The
>> ORDER BY clause does not guarantee ordered results when these constructs
>> are queried,
>> unless ORDER BY is also specified in the query itself
>> </quote>
>>
>> The only way to be sure is to use "Select * from vwMyView Order by
>> colMyCol"
>>
>>  _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
>
>



More information about the dba-SQLServer mailing list