For my requirement, I am creating one temporary table like below:
CREATE TABLE #ResourceMonthlyTimeReport
(
RowId INT IDENTITY(1,1),
ResourceID UNIQUEIDENTIFIER,
TaskId UNIQUEIDENTIFIER,
ProjectId UNIQUEIDENTIFIER,
-- Some column names containing date should come here.
)
In the above table, date columns should display like below:
[01 Mar, 2013] NVARCHAR(10),
[02 Mar, 2013] NVARCHAR(10),
[03 Mar, 2013] NVARCHAR(10),
... and the number of columns depends on the parameter values @FromDate and @ToDate
I have written a function dbo.F_ST_DaysColumns(@FromDate, @ToDate) that generates the following output as string:
[01 Mar, 2013] NVARCHAR(10),
[02 Mar, 2013] NVARCHAR(10),
[03 Mar, 2013] NVARCHAR(10)
Now, I am not understanding how to append this result to the above temporary table #ResourceMonthlyTimeReport.
I have done something like this:
DECLARE @DateColumns AS VARCHAR(MAX)
SET @DateColumns = dbo.F_ST_DaysColumns(@FromDate, @ToDate)
ALTER TABLE #ResourceMonthlyTimeReport ADD @DateColumns
But, showing error like below:
Msg 102, Level 15, State 1, Procedure ST_Proc_Rpt_MonthlyTimeReportSummary, Line 94
Incorrect syntax near '@DateColumns'