Hi,I want to use different table name every time while transpose data in my dynamic query[code="sql"]DECLARE @colsUnpivot AS NVARCHAR(MAX),@TableName NVarchar(MAX),@query AS NVARCHAR(MAX),@colsPivot as NVARCHAR(MAX),@Table_Name as Varchar(200),@fiscal_year as Varchar(4)SET @Table_Name = 'opd_lkp_scholar'SET @fiscal_year = '2015'select @colspivot = stuff((select ','+C.code_name from @Table_Name as C where C.fiscal_year = @fiscal_year for xml path('')), 1, 1, '')PRINT @colspivot[/code]It says "Msg 1087, Level 16, State 1, Line 11Must declare the table variable "@Table_Name"." But I have already declared the variable.Can anyone please help with this code? Thanks in advance.
↧