forked from csteelatgburg/K1000-Database-Queries
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassets - computer assets without an associated department.sql
More file actions
31 lines (28 loc) · 1.37 KB
/
Copy pathassets - computer assets without an associated department.sql
File metadata and controls
31 lines (28 loc) · 1.37 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
-- Report of computer assets without a department associated
-- Assumes:
-- the computer asset type has a custom field for the department asset type
-- Computers are assigned to users
-- Users have a custom field for their department
-- See comments below for custom field
SELECT ASSET.ID as 'ID',
ASSET.NAME as 'Asset Name',
MACHINE.NAME as 'Machine Name',
USER.FULL_NAME as 'Owner Name',
USER_DEPARTMENT.FIELD_VALUE as 'User Department',
ASSET_DEPARTMENT.NAME as 'Asset Department Name',
ASSET_DEPARTMENT.ID as 'Asset Department ID'
FROM ASSET
-- update the value of 10029 to the ASSET_FIELD_ID for the custom field ID on your SMA
-- This value is found in the ASSET_FIELD_DEFINITION table
LEFT JOIN ASSET_ASSOCIATION on ASSET_ASSOCIATION.ASSET_ID = ASSET.ID and ASSET_ASSOCIATION.ASSET_FIELD_ID = 10029
LEFT JOIN MACHINE on MACHINE.ID = ASSET.MAPPED_ID
LEFT JOIN USER on USER.ID = ASSET.OWNER_ID
-- update the value of 4 to the USER_FIELD ID
-- This value is found in the USER_FIELD_DEFINITION table
LEFT JOIN USER_FIELD_VALUE USER_DEPARTMENT on USER_DEPARTMENT.FIELD_ID = 4 and USER_DEPARTMENT.USER_ID = ASSET.OWNER_ID
LEFT JOIN ASSET ASSET_DEPARTMENT on ASSET_DEPARTMENT.NAME = USER_DEPARTMENT.FIELD_VALUE
WHERE ASSET_ASSOCIATION.ASSOCIATED_ASSET_ID is null
AND MACHINE.NAME is not null
AND ASSET.ASSET_TYPE_ID = 5
AND USER_DEPARTMENT.FIELD_VALUE != ''
AND ASSET_DEPARTMENT.ID is not null