Friday, September 21, 2007
« Who sucks at 64 bit, #1: Adobe CS2 | Main | Blogging for fun and proffit - Good tast... »

I came across the following example in Inside T-SQL Programming, which I am digesting at the moment.  Actually it is credited to Steve Kass (technical editor):

SELECT OrderId, OrderDate
FROM dbo.Orders
WHERE DATEDIFF(day, '19000102', OrderDate) % 7 = 0

This query is to answer the question "Which orders were placed on a Tuesday?".  The query isn't particularly magic, but the idea behind it is as close to the zen of T-SQL as I can remember seeing:

There are 7 days between any two Tuesdays.  If we know one Tuesday (like the 2nd Jan 1900) we have all the Tuesdays since.

What a great mindset to take with querying.

Listening To:   Places like this, Architecture In Helsinki