{"id":2263,"date":"2006-01-13T08:15:00","date_gmt":"2006-01-13T08:15:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/a-sql-limerick\/"},"modified":"2016-07-28T10:48:44","modified_gmt":"2016-07-28T10:48:44","slug":"a-sql-limerick","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/a-sql-limerick\/","title":{"rendered":"A SQL Limerick"},"content":{"rendered":"<div>It wasn&#8217;t my idea at all. However someone set me the challenge of writing executable code that rhymed and scanned in the form of a limerick. Obviously, the easy trick is to just to write the limerick, assign it to a string and then do text substitution on that striing to convert it into SQL code before executing it as a string. Sorry, cheating. You could also make sure your tables had entries that were defined once&#160;you&#8217;d written&#160;the limerick. Hmm. A bit unsporting. No. Straight to the north face of the Eiger for me. SQL in a directly executable form that executes against the sample PUBS database. After several spectacular failures, the best I could come up with was the following (&#8216;&gt;&#8217; has to be read as&#160;&#8217;greater than&#8217;.&#8217;)&#160; All I have done, I think, is to illustrate that it is possible. <\/div>\n<div>&#160;<\/div>\n<div><strong>Select advance,&#160; title, case when<br \/>price = 5000 then<br \/>&#8216;good&#8217; else &#8216;low&#8217; end<br \/>from titles WeSend<br \/>where pub_id &gt; 10<\/strong><\/div>\n<div>&#160;<\/div>\n<div>So can anyone do better? I believe that Red-Gate are willing to offer a prize for anyone who can do it. In which case, I am cheered by the thought that, if this blog entry is met by stunned silence in the comments, I shall claim the prize myself.<\/div>\n<div>&#160;<\/div>\n","protected":false},"excerpt":{"rendered":"<p>It wasn&#8217;t my idea at all. However someone set me the challenge of writing executable code that rhymed and scanned in the form of a limerick. Obviously, the easy trick is to just to write the limerick, assign it to a string and then do text substitution on that striing to convert it into SQL&#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-2263","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\/2263","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=2263"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2263\/revisions"}],"predecessor-version":[{"id":41353,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/2263\/revisions\/41353"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=2263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=2263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=2263"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=2263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}