[Solved] Insert into Temp Table from SQL Dynamic Results


all what i had to do is add this:
‘ into ##myTempTable

DECLARE @DynamicPivotQuery AS NVARCHAR(MAX)
DECLARE @ColumnName AS NVARCHAR(MAX)

--Get distinct values of the PIVOT Column 
SELECT @ColumnName = ISNULL(@ColumnName + ',','') + QUOTENAME([month]) 
FROM (SELECT DISTINCT [Month] FROM MyTable) AS [Month]
 order by [month]

--Prepare the PIVOT query using the dynamic 
SET @DynamicPivotQuery = 
  N'SELECT Mem_Name, ' + @ColumnName + ' into ##myTempTable 
    FROM MyTable   
    PIVOT(SUM(Amount) 
          FOR Month IN (' + @ColumnName + ')) AS PVTTable' 
--Execute the Dynamic Pivot Query
EXEC sp_executesql @DynamicPivotQuery 

solved Insert into Temp Table from SQL Dynamic Results