{"id":2575,"date":"2007-11-28T04:05:00","date_gmt":"2007-11-28T04:05:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/some-interesting-obscure-and-absolutely-useless-t-sql-syntax\/"},"modified":"2016-07-28T10:49:12","modified_gmt":"2016-07-28T10:49:12","slug":"some-interesting-obscure-and-absolutely-useless-t-sql-syntax","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/some-interesting-obscure-and-absolutely-useless-t-sql-syntax\/","title":{"rendered":"Some interesting, obscure (and absolutely useless) T-SQL syntax"},"content":{"rendered":"<p>\/*<br \/>Writing ugly SQL Statements is an art. Today I&#8217;ve spent<br \/>a few minutes trying to break our parser as well as giving <br \/>a grill to SQL Server&#8217;s parser.<br \/>So here is some extra syntax that is not behaving as <br \/>I&#8217;d expect it to behave. <br \/>*\/<\/p>\n<p>select 1.a<\/p>\n<p>&#8212; Yes, this is legal, surprise surprise it returns a <br \/>&#8212; table with a single column, a single row, the value<br \/>&#8212; is 1, the column name is &#8220;a&#8221; !<\/p>\n<p>&#8212; So let&#8217;s push it a bit further:<\/p>\n<p>select -1.a<\/p>\n<p>\/*<br \/>Works, the result is:<br \/>a<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>-1<br \/>*\/<\/p>\n<p>select -1\/2.[-1\/2]<\/p>\n<p>\/*<br \/>Wow, this works too, and it gives me <br \/>-1\/2<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>-0.500000<\/p>\n<p>So can I just put anything after the ?decimal? point?<br \/>*\/<\/p>\n<p>select 1.SomeString<\/p>\n<p>\/*<br \/>SomeString<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>1<br \/>*\/<\/p>\n<p>&#8212; But then there are exceptions:<br \/>select 1.a, 1.e, 0.a<\/p>\n<p>\/*<br \/>a&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; a<br \/>&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0.0<br \/>sa<\/p>\n<p>1.e does not produce the alias (e for exponent???),<br \/>0.a seems to use float, so the value displayed is 0.0<\/p>\n<p>It is a shame that you cannot use this with string literals.<br \/>Unless you want to torture your colleagues I reckon that <br \/>the above is absolutely useless. But if you have an idea why <br \/>the above works, and works the way it works, do let me know.<\/p>\n<p>PS: the above syntax works on 2000,2005 and 2008.<\/p>\n<p>&#160; Andras<br \/>*\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/*Writing ugly SQL Statements is an art. Today I&#8217;ve spenta few minutes trying to break our parser as well as giving a grill to SQL Server&#8217;s parser.So here is some extra syntax that is not behaving as I&#8217;d expect it to behave. *\/ select 1.a &#8212; Yes, this is legal, surprise surprise it returns a&#8230;&hellip;<\/p>\n","protected":false},"author":9298,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[],"class_list":["post-2575","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/9298"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=2575"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2575\/revisions"}],"predecessor-version":[{"id":41584,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2575\/revisions\/41584"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=2575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=2575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=2575"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=2575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}