In the previous post, we talked about pivoting logic to be implemented in the .Net logic. If we had sufficient access and if this was a small scale deployment where privileges to the tfs database can be provided, then the same pivoting operation described in the earlier post can be pushed down to SQL.
This is how it would look like:
CREATE TABLE [dbo].[Source](
[ID] [int] IDENTITY (1, 1) NOT NULL,
[owner] [nvarchar[(50) NOT NULL,
[WorkItemID] [int] NOT NULL,
[Priority] [int] NOT NULL) ON PRIMARY
INSERT INTO pvt VALUES (1,"abc",1);
INSERT INTO pvt VALUES (2,"def",2);
INSERT INTO pvt VALUES (3,"ghi",2);
INSERT INTO pvt VALUES (4,"jkl",3);
SELECT [Owner],
[1],
[2],
[3]
FROM
(SELECT Owner, WorkItemID, Priority FROM [dbo].[Source])
AS Src
PIVOT
(
COUNT(WorkItemID)
FOR Priority in ([1], [2], [3])
) AS PivotTable;
This is how it would look like:
CREATE TABLE [dbo].[Source](
[ID] [int] IDENTITY (1, 1) NOT NULL,
[owner] [nvarchar[(50) NOT NULL,
[WorkItemID] [int] NOT NULL,
[Priority] [int] NOT NULL) ON PRIMARY
INSERT INTO pvt VALUES (1,"abc",1);
INSERT INTO pvt VALUES (2,"def",2);
INSERT INTO pvt VALUES (3,"ghi",2);
INSERT INTO pvt VALUES (4,"jkl",3);
SELECT [Owner],
[1],
[2],
[3]
FROM
(SELECT Owner, WorkItemID, Priority FROM [dbo].[Source])
AS Src
PIVOT
(
COUNT(WorkItemID)
FOR Priority in ([1], [2], [3])
) AS PivotTable;
No comments:
Post a Comment