SQL order by required

There are subtle differences between Oracle, Sybase, mySQL, and SQL Server SQL syntax. Sybase seems to be the most forgiving or loose while Oracle’s and MS SQL Server’s syntax is very strict.

Yesterday I ran into an error that occurred because a new formatted field name was in the select statement with the as alias. The error claimed I needed an order by statement which I had. The SQL statement worked fine on the SYBASE queries but failed for SQL Server.

select convert(datetime, createdDate) as dateCreated, field, etc
from myTable...
order by convert(datetime, createdDate) <!-- correct syntax -->
...
NOT order by createdDate

In the case of using min(), max(), sum(), or concatenation statements a group by may also have been required in the same syntax as the aggregator.

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, SQL. Bookmark the permalink.