Re: Create table and default order by clause



Hi Davide,

The table is unordered set and you have to explicitly use ORDER BY if you
need to retrieve data in particular order. Even a view will not work, as you
cannot use ORDER BY in a view, unless the TOP clause is specified (and in
that case the ORDER BY is used only to determine the rows returned by the
TOP clause, you still have to use ORDER BY when selecting from the view to
return ordered set).

Since your software controls the creation of the temporary table, it may be
easier to add <sort> column to the table and to populate with values based
on the parameters. Then the report engine can still use static SQL, like
"SELECT <columns> FROM #MyTable ORDER BY sort".

HTH,

Plamen Ratchev
http://www.SQLStudio.com



.



Relevant Pages

  • Re: Subquery in the FROM clause
    ... klem s wrote: ... a FROM clause? ... as data source. ... Because a table is unordered set. ...
    (microsoft.public.sqlserver.programming)
  • Re: Creating a VIEW
    ... This is most likely because you added sort. ... A view is unordered set and the graphic tools unfortunately have inappropriate behavior to add ORDER BY and TOP. ...
    (microsoft.public.sqlserver.programming)