Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

How can store the data from temp variable to Table dynamically

$
0
0

Hi Visakh,

Below is My Query

/*Declare Variable*/  
DECLARE @Column [nvarchar](max);  
DECLARE @Query [nvarchar](max);  
  
/*Select Pivot Column*/  
SELECT @Column= COALESCE(@Column+',','')+ QUOTENAME([Date]) FROM  
(SELECT DISTINCT [Date] FROM [TEST].[dbo].[Product])Tab 

SELECT @Query='SELECT [ProductID],[ItemID], '+@Column+'FROM   
(SELECT [ProductID],[ItemID], [Date] , [Qty] FROM [TEST].[dbo].[Product] )Tab1  
PIVOT  
(  
SUM(Qty) FOR [Date] IN ('+@Column+')) AS Tab2  
ORDER BY Tab2.ProductID,[ItemID]' 

I need to store @Query results in table.Like below is the example 

select *  into temppfrom [TEST].[dbo].[Product]

Regards,

Niranjan B


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>