Fun With Dynamic SQL Statements

Today has been one of those Eureka days. While trying to work on a management report that includes data from multiple sources and requires calculation of Median statistics on a 2 dimensional table, I finally got around to playing with the sp_executesql statement that is part of SQL Server 2008. 

This funky command is allowing me to create a single, parameterized SQL statement that I can run.

The best resource I found, with useful examples is over at CodeProject.