Sorted view in SQL 2005

It looks like something new in SQL 2005. If you try to add a “order by” in the view, the management studio will automatically add a “TOP (100) PERCENT” after the SELECT clause. However this only works in “preview” mode. If you query “select * from [view_name]”, you still get the records unsorted.

To get the sorted records from a view, a workaround is to use
SELECT top 1000000000 * FROM

This is not ideal but it works if you know your data count range. Microsoft has a hotfix for this. I can’t believe MS let SQL 2005 out of the door with such a bug.

This entry was posted in SQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s