It wasn’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 you’d written 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 (‘>’ has to be read as ‘greater than’.’) All I have done, I think, is to illustrate that it is possible.
Select advance, title, case when
price = 5000 then
‘good’ else ‘low’ end
from titles WeSend
where pub_id > 10
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.