Transposing a table in SQL server

后端 未结 3 1066
梦毁少年i
梦毁少年i 2021-01-07 06:32

I am using SQL Server 2005 for my application. I have a table in my stored procedure which has two columns, C1 and C2. I want to transpose this table such that the values of

3条回答
  •  粉色の甜心
    2021-01-07 07:19

    This isnt exact result that you want but you can try this

    ;WITH TAB1 AS
    ( SELECT  [ResponsibleID] C1,[ActionID] C2,1 ORD
      FROM [TEST].[dbo].[yourtable]
      WHERE 1=1
      )
    
    
     SELECT 
        CASE WHEN M1=1 THEN ActionID ELSE NULL END M1,
        CASE WHEN M2=1 THEN ActionID ELSE NULL END M2 
     FROM TAB1
     PIVOT(AVG(ORD) FOR RESPONSIBLEID IN ([M1],[M2])) AS ABC
    

提交回复
热议问题