Wednesday, November 24, 2004

Cute SQL Workaround

This post will only interest some of you hardcore techies out there, but I just needed to share:

Normally, when creating a view in SQL, you can't include an ORDER BY clause to sort the results in a particular fashion. I needed to do this recently, and came up with two workarounds for this limitation:

1. Pre-sort the table: use something along the lines of


SELECT *
FROM (Select * from table order by column_1)



2. You Can order your view, if you use the Top clause. So:

SELECT TOP 100 PERCENT *
FROM TABLE
ORDER BY COLUMN1



No comments: