Can you make Common Table expressions in Lansweeper?
This can be done in a view and that is what Lansweeper make of the reports.
Or does anybody have an workaround for this?
Thanks for Tips.
This is to check if a user has the correct OU through all domains production is leading.
WITH CTE_Production
AS (
SELECT
tblADusers.Username+tblADGroups.Name as ID,
tblADusers.Username,
tblADusers.Userdomain,
tblADGroups.Name
FROM tblADusers
INNER JOIN tblADMembership On tblADusers.ADObjectID = tblADMembership.ChildAdObjectID
INNER JOIN tblADGroups On tblADMembership.ParentAdObjectID = tblADGroups.ADObjectID
WHERE
tblADusers.Userdomain = 'Production'
),
CTE_Test
AS (
SELECT
tblADusers.Username+tblADGroups.Name as ID,
tblADusers.Username,
tblADusers.Userdomain,
tblADGroups.Name
FROM tblADusers
INNER JOIN tblADMembership On tblADusers.ADObjectID = tblADMembership.ChildAdObjectID
INNER JOIN tblADGroups On tblADMembership.ParentAdObjectID = tblADGroups.ADObjectID
WHERE
tblADusers.Userdomain = 'Test'
),
CTE_Acceptance
AS (
SELECT
tblADusers.Username+tblADGroups.Name as ID,
tblADusers.Username,
tblADusers.Userdomain,
tblADGroups.Name
FROM tblADusers
INNER JOIN tblADMembership On tblADusers.ADObjectID = tblADMembership.ChildAdObjectID
INNER JOIN tblADGroups On tblADMembership.ParentAdObjectID = tblADGroups.ADObjectID
WHERE
tblADusers.Userdomain = 'Acceptance'
)
SELECT
CASE
WHEN CTE_Production.ID = CTE_Test.ID and CTE_Production.ID = CTE_Acceptance.ID THEN 'In Production and Test and Acceptance'
WHEN CTE_Production.ID = CTE_Test.ID and CTE_Acceptance.ID IS NULL THEN 'In Production and Test not in Acceptance'
WHEN CTE_Production.ID = CTE_Acceptance.ID and CTE_Test.ID IS NULL THEN 'In Production and Acceptance not in Test'
WHEN CTE_Production.ID IS NOT NULL and CTE_Acceptance.ID IS NULL and CTE_Test.ID IS NULL THEN 'In Production not in Test and not in Acceptance'
WHEN CTE_Test.ID = CTE_Acceptance.ID and CTE_Production.ID IS NULL THEN 'In Test and Acceptance not in Production'
WHEN CTE_Test.ID IS NOT NULL and CTE_Production.ID IS NULL and CTE_Acceptance.ID IS NULL THEN 'In Test not in Production and not in Acceptance'
WHEN CTE_Acceptance.ID IS NOT NULL and CTE_Production.ID IS NULL and CTE_Test.ID IS NULL THEN 'In Acceptance not in Production and not in Test'
END as [check],
CASE
WHEN CTE_Production.ID = CTE_Test.ID and CTE_Production.ID = CTE_Acceptance.ID THEN '#026625'
WHEN CTE_Production.ID = CTE_Test.ID and CTE_Acceptance.ID IS NULL THEN 'FFDF00'
WHEN CTE_Production.ID = CTE_Acceptance.ID and CTE_Test.ID IS NULL THEN '#000080'
WHEN CTE_Production.ID IS NOT NULL and CTE_Acceptance.ID IS NULL and CTE_Test.ID IS NULL THEN '#CC0033'
WHEN CTE_Test.ID = CTE_Acceptance.ID and CTE_Production.ID IS NULL THEN '#CC00##'
WHEN CTE_Test.ID IS NOT NULL and CTE_Production.ID IS NULL and CTE_Acceptance.ID IS NULL THEN 'FFDF00'
WHEN CTE_Acceptance.ID IS NOT NULL and CTE_Production.ID IS NULL and CTE_Test.ID IS NULL THEN '#000080'
END as [Backgroundcolor],
CTE_Production.ID as [IDPRD],
CTE_Production.Username as [UserNamePRD],
CTE_Production.Userdomain as [DomainPRD],
CTE_Production.Name as [OUPRD],
CTE_Test.ID as [IDTST],
CTE_Test.Username as [UserNameTST],
CTE_Test.Userdomain as [DomainTST],
CTE_Test.Name as [OUTST],
CTE_Acceptance.ID as [IDACC],
CTE_Acceptance.Username as [UserNameACC],
CTE_Acceptance.Userdomain as [DomainACC],
CTE_Acceptance.Name as [OUACC]
FROM CTE_Production
FULL OUTER JOIN CTE_Test on CTE_Production.ID = CTE_Test.ID
FULL OUTER JOIN CTE_Acceptance on CTE_Production.ID = CTE_Acceptance.ID
WHERE
CTE_Production.ID = CTE_Test.ID and CTE_Acceptance.ID IS NULL or
CTE_Production.ID = CTE_Acceptance.ID and CTE_Test.ID IS NULL or
CTE_Production.ID IS NOT NULL and CTE_Acceptance.ID IS NULL and CTE_Test.ID IS NULL or
CTE_Test.ID = CTE_Acceptance.ID and CTE_Production.ID IS NULL or
CTE_Test.ID IS NOT NULL and CTE_Production.ID IS NULL and CTE_Acceptance.ID IS NULL or
CTE_Acceptance.ID IS NOT NULL and CTE_Production.ID IS NULL and CTE_Test.ID IS NULL
ORDER BY
[check],CTE_Production.Username, CTE_Production.Userdomain