Hi friends,
I want to create a report something similar like excel pivot
The report at first sight should show me like this:
Row Labels | Sum of COL1 | Sum of COL2 | Sum of COL3 | Sum of COL4 | Sum of COL5 |
+101 | 11 | 14 | 10 | 19 | 10 |
+102 | 3 | 6 | 9 | 12 | 15 |
+103 | 4 | 8 | 12 | 16 | 20 |
+104 | 3 | 6 | 9 | 12 | 15 |
Grand Total | 21 | 34 | 40 | 59 | 60 |
When I click on (+) toggle the report should give me detailed data like this:
Values | |||||
Row Labels | Sum of COL1 | Sum of COL2 | Sum of COL3 | Sum of COL4 | Sum of COL5 |
101 | |||||
A | 1 | 2 | 3 | 4 | 5 |
B | 3 | 2 | 4 | 7 | 0 |
C | 6 | 8 | 0 | 4 | 0 |
D | 1 | 2 | 3 | 4 | 5 |
102 | |||||
A | 1 | 2 | 3 | 4 | 5 |
B | 1 | 2 | 3 | 4 | 5 |
C | 1 | 2 | 3 | 4 | 5 |
103 | |||||
A | 1 | 2 | 3 | 4 | 5 |
B | 1 | 2 | 3 | 4 | 5 |
C | 1 | 2 | 3 | 4 | 5 |
D | 1 | 2 | 3 | 4 | 5 |
104 | |||||
A | 1 | 2 | 3 | 4 | 5 |
B | 1 | 2 | 3 | 4 | 5 |
C | 1 | 2 | 3 | 4 | 5 |
Grand Total | 21 | 34 | 40 | 59 | 60 |
Below is the sample data:
CREATE TABLE [dbo].[SampleTable](
[ID] [int] NULL,
[COL0] [nvarchar](50) NULL,
[COL1] [int] NULL,
[COL2] [int] NULL,
[COL3] [int] NULL,
[COL4] [int] NULL,
[COL5] [int] NULL
) ON [PRIMARY]
GO
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (101, N'A', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (101, N'B', 3, 2, 4, 7, 0)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (101, N'C', 6, 8, 0, 4, 0)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (102, N'A', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (102, N'B', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (102, N'C', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (103, N'A', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (103, N'B', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (103, N'C', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (103, N'D', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (104, N'A', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (104, N'B', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (104, N'C', 1, 2, 3, 4, 5)
INSERT [dbo].[SampleTable] ([ID], [COL0], [COL1], [COL2], [COL3], [COL4], [COL5]) VALUES (101, N'D', 1, 2, 3, 4, 5)
Please Mark as Answer if my post solved your problem or Vote As Helpful if this helps. Blogs: www.sqlserver2005forum.blogspot.com