A quick rant about SQL Server. I was designing a view the other day and decided that I want the default select on the view to be in a certain order. I use that view in turn inside another view using a Union All statement.
In my first view I add in a SELECT statement like this: SELECT fielda, fieldb, fieldc FROM tablename ORDER BY fieldc, fielda. Now, in a regular select statement this gives me the results I want. Everything neatly arranged the way I want it. However, when I try to save the view I get an error message that says "Warning: The ORDER BY clause is used only to determine the rows that are returned by the TOP clause in the view definition. The ORDER BY clause does not guarantee ordered results when the view is queried, unless ORDER BY is also specified in the query itself." Wait, what?!?!? The sole purpose for using a view is to view the data. Why can't I have the default view of the data ordered before the view is passed on to the end user? I realize that I can rewrite my select statement to create a temporary table, insert everything I need into that table using a select from, order by statement and then do a select all from that table and then I have to dispose of the temporary table.
That seems like an awful lot of overhead just to order my output results.
No comments:
Post a Comment