Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. CREATE TABLE [dbo].[Details]( [ID] [int] IDENTITY(1,1) NOT NULL, [Type] [nvarchar](10) NOT NULL, [Header] [nvarchar](50) NOT NULL, [SubHeader] [nvarchar](50) NOT NULL, [January] [decimal](18, 2) NOT NULL, [February] [decimal](18, 0) NOT NULL, [March] [decimal](18, 2) NOT NULL, [April] [decimal](18, 2) NOT NULL, [May] [decimal](18, 2) NOT NULL, [June] [decimal](18, 2) NOT NULL, [July] [decimal](18, 2) NOT NULL ) ON [PRIMARY]
  2.  
  3. GO SET IDENTITY_INSERT [dbo].[Details] ON
  4.  
  5. GO INSERT [dbo].[Details] ([ID], [Type], [Header], [SubHeader], [January], [February], [March], [April], [May], [June], [July]) VALUES (2, N'Regular', N'Item-1', N'A.Sub-Item1', CAST(64.92 AS Decimal(18, 2)), CAST(57 AS Decimal(18, 0)), CAST(89.67 AS Decimal(18, 2)), CAST(99.20 AS Decimal(18, 2)), CAST(76.34 AS Decimal(18, 2)), CAST(23.33 AS Decimal(18, 2)), CAST(32.23 AS Decimal(18, 2))) GO INSERT [dbo].[Details] ([ID], [Type], [Header], [SubHeader], [January], [February], [March], [April], [May], [June], [July]) VALUES (3, N'Irregular', N'Item-1', N'A.Sub-Item1', CAST(43.45 AS Decimal(18, 2)), CAST(65 AS Decimal(18, 0)), CAST(65.88 AS Decimal(18, 2)), CAST(56.77 AS Decimal(18, 2)), CAST(45.65 AS Decimal(18, 2)), CAST(56.87 AS Decimal(18, 2)), CAST(67.55 AS Decimal(18, 2))) GO SET IDENTITY_INSERT [dbo].[Details] OFF GO
  6.  
  7. SELECT Header, SubHeader,
  8. Regular, Irregular,
  9. FRegular, FIrregular,
  10. MrRegular, MrIrregular
  11. FROM (SELECT Header, SubHeader, Type, 'F'+Type AS FType, 'Mr'+Type as MType, 'Ap'+Type AType, 'Ma'+Type as May,
  12. [January], [February], [March]
  13. from [CashFlow].[dbo].[Details] ) p
  14.  
  15. PIVOT (MAX(January) FOR Type in (Regular, Irregular)) AS JPVT
  16. PIVOT (MAX([February]) FOR FType in (FRegular, FIrregular)) AS FPVT
  17. PIVOT (MAX(March) FOR MType in (MrRegular, MrIrregular)) AS MrPVT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement