A few SQL Rules
I just came across Jeff Smith's post (thanks to Darren). I like Jeff's advice. I'm pleased to say that I do all this - despite the odd bit of flak I might take over my use of derived tables. I think derived tables are great.
The very fact that Jeff has made a post like this tells me there are a bunch of people out there who don't do these things, and that makes me really sad. It really frustrates me when people do nasty nasty stuff with their queries, and I often feel like people approach writing a query like they would approach an API. But anyway, I like Jeff's rules.
Here's a thing I quite like these days...
select
'colname1' = whatever1,
'colname2' = whatever2,
etc...
as opposed to:
select
whatever1 colname1,
whatever2 colname2,
etc...
Giving my columns names this way (the first way) means that all my column names are lined up nicely, and even all the definitions are lined up nicely, assuming I hit tab before the equals sign. It means that when I come to glancing at the query, I can see exactly what the result columns are - and this really helps in my derived tables too!