Searching for the Wildcard Percentage Symbol in SQL Server – when it’s being itself

When searching data stored in a table in an SQL Server database you create queries such as…

Select * from tbl_document were document_name like ‘File %’

This will return all documents with a filename starting with the word File and a space followed by anything. That’s what the % represents – anything, anything at all.

Anything is quite a big concept for a line and two circles when you think out it

But what if you want to search for the % character itself – when it’s having a day off from being the all encompassing wildcard of wonder and it just being a plain, simple percentage?

I had to find all documents in the database that had been uploaded with %20 in the filename – I’ve done this before but for the life of me I couldn’t remember how – so I went to Google but alas the search gods were not smiling on me – so I asked Twitter.

The knights in shining armour that are Ian Field (@IanField90) and Peter Curd (@PCurd) rushed to my rescue with the solution…

where document_name like ‘%[%]%’

This will match anything-percentage-anything.

Once again, knowing the right people on twitter helps. Ok so I’ve met both of these charming gents in real life, but I also received help and suggestions from others who I haven’t.

Happy Querying!

Surprise Dining Algorithm Problem

All I have to do is organise 16 dinner parties… how hard can it be?

The Rotary Club of Reading Abbey have a season of Surprise Dining, each couple signed up will host one dinner party and go to three others. The host of the dinner party does the main course, the other guests do the starter, pudding and cheese. Each couple involved will cook an entire meal but in stages.

The Rules
– Each couple will attend 4 dinner parties
– Each couple will do the Main Course once, Starter once, Pudding once, Cheese once
– Each couple should only encounter the other guests once at the dinner parties (you only have dinner with couple A once, not meeting them again)

So… is this possible?

If So… there has to be an algorithmic answer to this… I look to you stats-based people for help!

I need 16 combinations of the letters A to P where each letter is in position 1 (starter), 2 (main), 3(pudding) and 4(cheese) only once. AND there are no repeating combinations of letters – so a,b,c,d and b,a,e,f wouldn’t work as a and b have already seen each other the previous week.

Any and all ideas gratefully received!

You’d be amazed what you can do with a frozen banana

Humans are wonderful creatures, almost any issue you have, someone else will have had it before you – and now thanks to the internet, you can find these people and read blog posts about how they dealt with it, you can message them on twitter and talk to them about it. Sometimes we forget just how amazing this is.

This is amazing, even when we’re talking about the rather bizarre problem of what to do with frozen bananas.

We are all familiar with the concept of testers, these are wonderfully honest people that go though your applications and find all the bugs, niggles and irks for you to fix. They can be frustrating people but oh-so-useful. I am lucky enough have my own panel of testers -  dedicated, hard working people that, for the sake of friendship and honour, allow me to try out new recipes on them. I love each and every one of them. The "mmmm, that’s not bad" from them is the highest accolade a cook can have, it’s like an addiction – alas this is something I have given up for the moment…

My good friend Ben is currently taking part in a very worthwhile challenge – Lay off the Cake – he and his colleague are competing to see who can lose the most weight. Out of respect and in support of this I have refrained from baking fat laden goodies when I know he will be around – it’s been surprisingly hard – but last week I discovered something rather wonderful…

For reasons too mundane to go into here I had shoved some rather ripe bananas into my freezer before going away for the weekend. The natural consequence of this is that last Monday found me googling (Yes, Googling….) the phrase "Frozen banana recipes". What I found was rather remarkable.

How To Make Creamy Ice Cream with Just One Ingredient! – from

It turns out that if you blend a Frozen Banana and nothing else it turns into something with the texture and taste of ice cream.

I know… that’s the exact expression of incredulity I had.

After this expedition into the crazier side of the internet I met up with Katherine “The Sorceress” Robinson and told her this tale. She also instantly screwed her face into the classic ‘You can’t make ice cream from frozen bananas’ expression but we thought it was worth a try. Home we went and – as all good scientists must do before an experiment – made tea.

With the comforting wafts and warmth of Yorkshire Tea to bolster us we went for it. The first thing we learnt – pealing a frozen banana is not an easy task.


Eventually the chopped frozen banana was in the plastic prison of my Kenwood Mini Chopper, lid in place. We shared the by-now familiar expression of ‘You can’t make ice cream from frozen bananas’ and pressed the button…


We got chopped banana. We were significantly underwhelmed.

But we had gone too far to give up now. After the effort that went into peeling the thing it was personal. So, more blending… This time we got finer chopped banana. The cause was lost, we were just making a mess now. We silently vowed to never believe anything the harpy that is the internet said ever again. That purveyor of broken promises and dreams was dead to us.

Without any hope in my heart I gave it just one final blast of the blender and the magic happened. Suddenly. Peacefully. The chopped banana collapsed in on itself and turned creamy with barely a sigh as it let go if it’s solid form and relaxed into creamy goodness.


We had ice cream.

Teaspoons. Tasting. Raised eyebrows. Incredulity. This was ice cream! This was Fat-Free ice cream. This was Ice Cream with all the nutritional merits of a banana and nothing else. In that one taste we forgave the internet and let it back into our hearts.

Then the best bit. Ben arrived. Once again I got to do something I love – feed something yummy to someone who loves their food and suddenly, all was right with the world once more.


The FizzBuzz Problem and Diving in Too Soon

One of my developer friends – Nick Telford – tweeted this article about Programmers and the lack of those that seem able to programme.

Will The Real Programmers Please Stand Up? // another example of how diluted our industry really isless than a minute ago via TweetMeme

This article linked to anothe one – Why can’t programmers…program? – which mentioned the FizzBuzz problem.

The idea is simple, all you have to do is write a program that prints out the numbers 1 to 100, but for multiples of 3, print Fizz instead of the number and for multiples of 5 print Buzz. If the number is a multiple of both, FizzBuzz should be printed.

So here’s my answer – in php of course.

  1. <?php
  2. $x = 100;
  3. for ($i=1; $i<=$x; $i++) {
  4.     $msg = "";
  5.     if ($i % 3 == 0) {
  6.         $msg = "Fizz";
  7.     }
  8.     if ($i % 5 == 0) {
  9.         $msg = $msg . "Buzz";
  10.     }
  11.     if (strlen($msg) == 0) {
  12.         $msg = $i;
  13.     }
  14.     print $msg . "<br/>";
  15. }
  16. ?>

This complies with all 4 of the requirements (numbers, Fizzes, Buzzes and FizzBuzzes), which is the point – many developers when set this task miss out one or more of the vital parts clearly stated in the specification.

It all goes back to what your mother told you when you had your first exam at school – remember to read the entire question first before diving in.

So did I miss something? Can you do it more efficiently?