-
Notifications
You must be signed in to change notification settings - Fork 0
/
uspGetSCCMReportData.sql
41 lines (37 loc) · 1.06 KB
/
uspGetSCCMReportData.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
31
32
33
34
35
36
37
38
39
40
41
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [automation].[uspGetSCCMReportData]
AS
SET NOCOUNT ON;
BEGIN
DECLARE
@COLUMNS VARCHAR(MAX),
@SqlStatement VARCHAR(MAX)
SELECT
@COLUMNS = coalesce(@COLUMNS + ', ', '') + '[' + convert(varchar(255),PropertyName) + ']'
FROM
DeviceExtensionRegistration
ORDER BY
PropertyName
SET @SqlStatement = N'select * from (
select
vSMS_R_SYSTEM.ItemKey,
vSMS_R_SYSTEM.Client_Type0,
vSMS_R_SYSTEM.Name0,
vSMS_R_SYSTEM.SMS_Unique_Identifier0,
vSMS_R_SYSTEM.Resource_Domain_OR_Workgr0,
vSMS_R_SYSTEM.Client0,
v_SMS_G_System_ExtensionData.PropertyName,
v_SMS_G_System_ExtensionData.PropertyValue
from vSMS_R_System left join v_SMS_G_System_ExtensionData
on v_SMS_G_System_ExtensionData.ResourceId = vSMS_R_System.ItemKey) t
pivot
(
MAX(PropertyValue) FOR PropertyName IN ('+ @COLUMNS +')
)
AS PivotTable;'
EXEC(@SqlStatement)
END
GO