Hi,I have SP as below, my column name is depend on date input. How can I create SSRS report dataset since I have no static column name?Refer 2 example table column name with 2 different input:http://oi44.tinypic.com/141a87.jpgCreate procedure CALENDARFY_Display (@START_DATE DATETIME,@ENDDATE DATETIME) AS--exec CALENDARFY_Display '2011-04-01', '2012-03-31'--DECLARE @START_DATE DATETIME--DECLARE @ENDDATE DATETIME--SET @START_DATE = '2011-04-01'--SET @ENDDATE = '20120331';delete from CALENDARBEGINWITH CTE_DATES AS(SELECT @START_DATE DateValue UNION ALL SELECT DateValue + 1FROM CTE_DATESWHERE DateValue + 1 <= @ENDDATE)INSERT INTO CALENDAR (Dates) SELECT CAST(DateValue AS date) FROM CTE_DATES OPTION (MAXRECURSION 0)END drop table tempp select Dates=replace(convert(varchar(10), c.Dates, 120),'-','')+'|'+datename(weekday, c.Dates ), e.UserName,Descsinto tempp from Calendar cleft join (SELECT id,Dt,u.UserName,Descs=cast(isnull([text],'') as varchar)+'-'+cast(Isnull(room_id,'') as varchar) from events eleft join aspnet_Users u on u.[userId]=e.[user_id] CROSS APPLY fnGetDatesInRange([Start_Date], End_Date)) e on convert(varchar(10), Dt, 120)=c.Dateswhere dates between @START_DATE and @ENDDATEDECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX)select @cols = STUFF((SELECT distinct ',' + QUOTENAME(Dates) from tempp FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'')set @query = 'SELECT UserName ,' + @cols + ' from ( select Dates, UserName, Descs from tempp ) x pivot ( max(Descs) for Dates in (' + @cols + ') ) p where UserName is not null'execute(@query)
Please advise.Regards,Micheale