-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pivot titles for Ind Rept search.sql
30 lines (23 loc) · 1.13 KB
/
Pivot titles for Ind Rept search.sql
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
select i.id, employeename, locationcode, employeebadge, e.OtherTitle from IndividualReporting i
join IndividualReportingElements e on i.Id = e.IndReptId
where employeename like '%gao%' or employeebadge like '%gao%' or locationcode like '%gao%'
DECLARE @PivotColumns AS NVARCHAR(MAX)
SELECT @PivotColumns= COALESCE(@PivotColumns + ',','') + QUOTENAME(OtherTitle)
FROM (select e.OtherTitle from IndividualReporting i
join IndividualReportingElements e on i.Id = e.IndReptId
where i.id = '4CEAA44F-9CB8-4E3B-A2CF-D7336884A2C0'
) AS PivotExample
select @PivotColumns
select @PivotColumns =
COALESCE(@PivotColumns + ',','') + QUOTENAME(OtherTitle)
FROM (select e.OtherTitle from IndividualReporting i1
join IndividualReportingElements e on i1.Id = e.IndReptId
where i1.id = '4CEAA44F-9CB8-4E3B-A2CF-D7336884A2C0')
as e1
select i.id, employeename, locationcode, employeebadge, (
select
COALESCE(OtherTitle + ',','') + QUOTENAME(OtherTitle)
FROM (select e.OtherTitle from IndividualReporting i1
join IndividualReportingElements e on i1.Id = e.IndReptId
where i1.id = '4CEAA44F-9CB8-4E3B-A2CF-D7336884A2C0')
as e1) from IndividualReporting i