{"id":2276,"date":"2006-03-01T02:45:00","date_gmt":"2006-03-01T02:45:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/palindromic-transact-sql\/"},"modified":"2016-07-28T10:48:46","modified_gmt":"2016-07-28T10:48:46","slug":"palindromic-transact-sql","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/palindromic-transact-sql\/","title":{"rendered":"Palindromic Transact SQL"},"content":{"rendered":"<p>Palindromes are words or phrases that read the same backwards and forwards. By the same token, Palindromic SQL executes just as well backwards and forwards<\/p>\n<p>A phrase such as &#8230;  <\/p>\n<ul>\n<li>&#8220;Did I do, O God, did I as I said I&#8217;d do? Good, I did&#8221;  <\/li>\n<li>&#8220;Marge lets Norah see Sharon&#8217;s telegram&#8221;  <\/li>\n<li>&#8220;No, son, onanism&#8217;s a gross orgasm sin: a no-no, son&#8221; <\/li>\n<\/ul>\n<p>&#8230; is a palindrome  <\/p>\n<p>You&#8217;ll notice that punctuation is allowed in palindromes. This means that one can actually construct palindromes fairly simply in Transact SQL, using the PUBS database. For example, the following&#8230;<\/p>\n<p><b>Select zip [srohtua morf] from authors [piz tceles]<\/b><\/p>\n<p>will execute happily in either direction just as long as you move the brackets. It is cheating of a sort, though not so brazen as Stephen Fry&#8217;s  <\/p>\n<p>&#8220;Rettebs, I flahd noces, eh? Ttu, but the second half is better.&#8221;  <\/p>\n<p>or the dreadful <\/p>\n<p> &#8220;My girlfriend has a freaking weird name: Eman Driewgnikaerfasahdneirflrigym.&#8221;  <\/p>\n<p>using the same detestable cheating trick one could come up with&#8230;<\/p>\n<p><b>Select title, pub_name from (select title, pub_name from titles inner join publishers on titles.pub_ID=publishers.pub_ID) [)DI_bup.srehsilbup=DI_bup.seltit no srehsilbup nioj renni seltit morf eman_bup ,eltit tceles( morf eman_bup ,eltit tceleS]<\/b><\/p>\n<p>As if to legitimise the construction of palindromes, Transact SQL Even has a string function <b>Reverse<\/b> that makes the whole process easier <\/p>\n<p>There was, for a short while, a craze for asking interview candidates to write code that checked the validity of a palindrome. It is a silly question, as it is hardly in the van of commercial applications for SQL. I&#8217;d prefer to ask questions&#160;that are of&#160;direct relevance to the rough and tumble of commercial SQL programming. However, I&#8217;d be delighted if someone could provide a model answer by writing the shortest palindrome checker in Transact SQL. Remember that some of the most famous palindromes ignore spaces, capitalisation&#160;and punctuation. In the meantime, what other tricks can one use for writing palindromic SQL that executes on the PUBS database? String literals? Comments? Executable strings? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Palindromes are words or phrases that read the same backwards and forwards. By the same token, Palindromic SQL executes just as well backwards and forwards A phrase such as &#8230; &#8220;Did I do, O God, did I as I said I&#8217;d do? Good, I did&#8221; &#8220;Marge lets Norah see Sharon&#8217;s telegram&#8221; &#8220;No, son, onanism&#8217;s a&#8230;&hellip;<\/p>\n","protected":false},"author":154613,"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-2276","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\/2276","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\/154613"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=2276"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2276\/revisions"}],"predecessor-version":[{"id":41365,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2276\/revisions\/41365"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=2276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=2276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=2276"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=2276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}