-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpivot-example.sql
More file actions
33 lines (33 loc) · 1.04 KB
/
pivot-example.sql
File metadata and controls
33 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
DECLARE @Matter AS NVARCHAR(50) = '16113-0%AU%'
SELECT
[pvt].[MatterID]
,[pvt].[Billing]
,[pvt].[Supervising]
,[pvt].[Handling]
,[pvt].[Foreign Paralegal]
,[pvt].[IDS Paralegal]
,[pvt].[US Paralegal]
FROM
(
SELECT
[m].[MatterID]
,[mp].[AssignedType]
,[p].[Initials]
FROM [dbo].[Matters] [m]
INNER JOIN [dbo].[MattersProfessionals] [mp] ON [mp].[Matters] = [m].[Matters]
INNER JOIN [dbo].[Professionals] [p] ON [p].[Professionals] = [mp].[Professionals]
WHERE [mp].[AssignedType] IN
(
'Billing', 'Supervising', 'Handling', 'Foreign Paralegal', 'IDS Paralegal', 'US Paralegal'
)
AND [m].[MatterID] LIKE @Matter
) AS [mp]
PIVOT
(
MIN([mp].[Initials])
FOR [mp].[AssignedType] IN
(
[Billing], [Supervising], [Handling], [Foreign Paralegal], [IDS Paralegal], [US Paralegal]
)
) AS [pvt]
ORDER BY [pvt].[MatterID]