|
Posted by Dan Guzman on 11/26/07 13:53
> So, I'm asking if there is a way to define, for a table, a default "order
> by" clause to use when no "order by" clause is specified in a "select"
> query
> statement on that table.
>
No, the only way to guarantee result order is to specify ORDER BY in the
SELECT statement that selects from the table.
> If not, I think the only alternative is to create a view on that table. Is
> it correct?
No, the only way to guarantee result order is to specify ORDER BY in the
SELECT statement that selects from the view. Although ORDER BY can be
specified in a view along with TOP, it will not guarantee ordering.
Note that it is likely, but not guaranteed, that you will get results
ordered in sequence by the table's clustered index in a trivial query with
no joins or where clause. However, it's risky to rely on behavior because
it may change between SQL Server service packs and releases.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"D." <d@d.com> wrote in message
news:CQz2j.6583$r62.2270@tornado.fastwebnet.it...
> Hi,
> I have this problem.
>
> My software creates a temporary table (#MyTable).
> This table should be used by a report engine and printed each time with
> different "order by" clause, depending on some parameters (and the program
> that creates the temporary table obviously knows these parameters...)
>
> Now, I don't want to pass these paramete to the report engine, because I
> want that the logic of the report will stay only in the program that
> create
> the table (the report engine should onnly do a "SELECT * FROM #MyTable").
>
> So, I'm asking if there is a way to define, for a table, a default "order
> by" clause to use when no "order by" clause is specified in a "select"
> query
> statement on that table.
>
> If not, I think the only alternative is to create a view on that table. Is
> it correct?
>
> Thanks,
> Davide.
>
>
>
>
[Back to original message]
|