I have the following code in a dynamic sql statement. I need some help where to put a "where" statement. I only want to include where the year = 2013 and the month = 3. Where should I include this parameter in the query?
Declare @strSQL varchar(max)
DECLARE @cols varchar(2000)
SELECT @cols = STUFF(( SELECT DISTINCT
'],[' + cast(Level3 as varchar)
ORDER BY 1
FOR XML PATH('')
), 1, 2, '') + ']'
set @strSQL = 'select YEAR, MONTH, ' + @cols +
' from (
select YEAR, MONTH, Level3, UTILIZED
pivot (COUNT(UTILIZED) for Level3 in (' + @cols + '))p'