Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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]
- GO SET IDENTITY_INSERT [dbo].[Details] ON
- 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
- SELECT Header, SubHeader,
- Regular, Irregular,
- FRegular, FIrregular,
- MrRegular, MrIrregular
- FROM (SELECT Header, SubHeader, Type, 'F'+Type AS FType, 'Mr'+Type as MType, 'Ap'+Type AType, 'Ma'+Type as May,
- [January], [February], [March]
- from [CashFlow].[dbo].[Details] ) p
- PIVOT (MAX(January) FOR Type in (Regular, Irregular)) AS JPVT
- PIVOT (MAX([February]) FOR FType in (FRegular, FIrregular)) AS FPVT
- PIVOT (MAX(March) FOR MType in (MrRegular, MrIrregular)) AS MrPVT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement