{"id":198,"date":"2010-06-02T07:25:30","date_gmt":"2010-06-02T11:25:30","guid":{"rendered":"http:\/\/erics-test-lab.com\/?p=198"},"modified":"2010-06-02T07:25:30","modified_gmt":"2010-06-02T11:25:30","slug":"sql-order-by-required","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2010\/06\/sql-order-by-required\/","title":{"rendered":"SQL order by required"},"content":{"rendered":"<p>There are subtle differences between Oracle, Sybase, mySQL, and SQL Server  SQL syntax. Sybase seems to be the most forgiving or loose while Oracle&#8217;s and MS SQL Server&#8217;s syntax is very strict.<!--more--><\/p>\n<p>Yesterday I ran into an error that occurred because a new formatted field name was in the select statement with the <strong>as alias<\/strong>. The error claimed I needed an <strong>order by<\/strong> statement which I had. The SQL statement worked fine on the SYBASE queries but failed for SQL Server.<\/p>\n<p><code>select convert(datetime, createdDate) as dateCreated, field, etc<br \/>\nfrom myTable...<br \/>\n<strong>order by convert(datetime, createdDate)<\/strong> &lt;!-- correct syntax --><br \/>\n...<br \/>\nNOT <span class=\"red\">order by createdDate<\/span> <\/code><\/p>\n<p>In the case of using min(), max(), sum(), or concatenation statements a <strong>group by<\/strong> may also have been required in the same syntax as the aggregator. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are subtle differences between Oracle, Sybase, mySQL, and SQL Server SQL syntax. Sybase seems to be the most forgiving or loose while Oracle&#8217;s and MS SQL Server&#8217;s syntax is very strict.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,14],"tags":[],"class_list":["post-198","post","type-post","status-publish","format-standard","hentry","category-code","category-sql"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=198"}],"version-history":[{"count":0,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/198\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}