I have the following query:
SELECT
S1.Node
,S1.DetailsUrl AS [_LinkFor_Node]
,'/Orion/images/StatusIcons/small-' + ToString(S1.StatusIcon) AS [_IconFor_Node]
,S1.IP
,S1.DetailsUrl AS [_LinkFor_IP]
--,S1.Area
,S1.MachineType
,S1.Version
,S1.Serial
,S1.LastBoot
,S1.LoginStatus
,S1.LastRunning
,S2.LastStartup
FROM(
SELECT
MAX(ca.DownloadTime) AS LastRunning
,ca.NodeProperties.CoreNodeID
,ca.NodeProperties.Nodes.Caption AS Node
,ca.NodeProperties.Nodes.StatusIcon
,ca.NodeProperties.Nodes.DetailsUrl
,ca.NodeProperties.Nodes.IPAddress AS IP
,ca.NodeProperties.Nodes.MachineType
--,ca.NodeProperties.Nodes.
,CASE
WHEN ca.NodeProperties.LoginStatus LIKE '%Cannot Log into Device : bad password%' THEN 'Error: Bad Password'
WHEN ca.NodeProperties.LoginStatus LIKE '%Connection Refused by%' THEN 'Connection Refused'
ELSE ca.NodeProperties.LoginStatus
END AS LoginStatus
,ca.NodeProperties.Nodes.IOSVersion AS Version
,ca.NodeProperties.Nodes.IOSImage AS Serial
,ca.NodeProperties.Nodes.LastBoot
-- ,ca.NodeProperties.Nodes.CustomProperties.Area
--,ca.NodeProperties.Nodes.CustomProperties.
FROM NCM.ConfigArchive AS ca
WHERE ca.ConfigType='Running'
-- AND ca.NodeProperties.Nodes.Vendor LIKE '%Juniper%'
GROUP BY ca.NodeProperties.CoreNodeID,ca.NodeProperties.LoginStatus,ca.NodeProperties.Nodes.Caption,ca.NodeProperties.Nodes.NodeID,ca.NodeProperties.Nodes.IPAddress,ca.NodeProperties.Nodes.MachineType,ca.NodeProperties.Nodes.IOSVersion,ca.NodeProperties.Nodes.IOSImage,ca.NodeProperties.Nodes.LastBoot,ca.NodeProperties.Nodes.StatusIcon,ca.NodeProperties.Nodes.DetailsUrl
) AS S1
INNER JOIN(
SELECT
MAX(ca.DownloadTime) AS LastStartup
,ca.NodeProperties.CoreNodeID
FROM NCM.ConfigArchive AS ca
WHERE ca.ConfigType='Startup'
-- AND ca.NodeProperties.Nodes.Vendor LIKE '%Juniper%'
GROUP BY ca.NodeProperties.CoreNodeID
) AS S2 ON S1.CoreNodeID=S2.CoreNodeID
What I'd really like to do is shrink the report to just devices that don't have a backup in the last 4 weeks based on these two fields: S1.LastRunning and/or S2.LastStartup.
Can anyone help?