Writing SQL with SQL

Mark Clerget of the Consultants Guild has a great post on generating SQL using SQL. Many moons ago Mark taught me this trick and it has served me well over the years.

Ever feel left behind when one of those SQL Server jockies breezes through a complex query that generates SQL on the fly? After all its a bit over the top to use SQL to generate SQL, isn't it? Well, its time to level the playing field. I'm going to pass on a simple pattern that you can use to generate the most sophisticated queries. This pattern will lead to an endless supply of SQL/Database tools to add to your library.