CREATE TABLE #tempcloum(
    [productNum] varchar(20)  null,
    [year1] decimal not null,
    [year2] decimal not null,
    [year3] decimal not null    
)
--лляD┴л
DECLARE @sql VARCHAR(800)
SET @sql = 'SELECT [productNum],'   
SELECT @sql = @sql + 'SUM(CASE [year] WHEN '''+[year]+''' THEN [price] ELSE 0 END) AS '''+[year]+''','   
FROM (SELECT DISTINCT [year] FROM #tempYear) AS a     
SELECT @sql = LEFT(@sql,LEN(@sql)-1) + ' FROM #tempYear  GROUP BY [productNum] '
PRINT(@sql)

insert into #tempcloum
   
EXEC(@sql)
GO

 

相关文章:

  • 2021-05-26
  • 2021-08-21
  • 2021-09-05
  • 2022-12-23
  • 2021-06-28
  • 2021-12-22
猜你喜欢
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-12-30
相关资源
相似解决方案