I just finished with a Dynamic SP (With some help from some members here) and I am trying to find out if it is possible to have dynamic columns on a SSRS report. The procedure I am using is the following:set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER Procedure [dbo].[spOpenMonthly] @prmStartDate datetime, @prmEndDate datetimeASDECLARE @listCol VarChar(2000)DECLARE @query VarChar(max)SELECT @listCol = Stuff((SELECT DISTINCT '],[' + ltrim(Month_Open+ ' '+Year_Open) FROM ClaimsOpenView01 WHERE EntryDate >= convert(varchar, @prmStartDate) AND EntryDate < convert(varchar, @prmEndDate+1) ORDER BY '],['+ ltrim(Month_Open+ ' '+Year_Open) FOR XML PATH('') ), 1, 2, '') + ']'SET @query='SELECT * FROM (SELECT Contract_Name, Year# =Month_Open +'+ ''' '''+' + Year_Open, ClaimNum FROM ClaimsOpenView01 WHERE EntryDate >= '''+ convert(varchar, @prmStartDate)+''' AND EntryDate < '''+ convert(varchar, @prmEndDate+1)+''') srcPIVOT (count(ClaimNum) FOR Year# IN ('+@listCol+')) AS pvt'EXECUTE (@Query)
What the sp does is get a date range from a user and then reports back the number of claims open by month for each contract. So if someone put in the date range of 1/1/09 to 4/1/09 you would get something back like:Contract January 2009 February 2009 March 2009 April 2009Con1 4 2 1 0Con2 10 0 5 7Con3 3 1 4 9Obviously the month/year across the top is entirely dependent on what the user puts in. Is there any way to make it so the month/year will populate in the report when a user puts in the dates?Thanks