SQL: Column to Row

CREATE TABLE #t(  
----[PKID] int primary key identity(101,1),  
    [iyear] [Nvarchar](4) NOT NULL,  
    [budget1] [int] NOT NULL,  
    [budget2] [int] NOT NULL,  
    [budget3] [int] Not Null  
    )  
GO  
INSERT #t  
SELECT '2016',100000,12676575,3623232
GO  
SELECT * FROM #t

SELECT iyear as year,replace(bm,'budget','') as month,budget as budget
FROM  #t  
UNPIVOT(budget FOR bm IN (budget1,budget2,budget3) ) p

 result:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326320604&siteId=291194637