Hello.
I'm having trouble making up a query for software metering. The query was adopted from some site and then modified to suit my purposes. I am however having problems adding a simple where-clause to this query.
The query is as follows:
Select SMS_R_System.ResourceID,SMS_R_System.Name,SMS_R_User.UniqueUserName
FROM SMS_R_System
JOIN SMS_UserMachineRelationship ON SMS_R_System.Name=SMS_UserMachineRelationship.MachineResourceName
JOIN SMS_R_User ON SMS_UserMachineRelationship.UniqueUserName=SMS_R_User.UniqueUserName
INNER JOIN SMS_G_System_SoftwareFile ON SMS_G_System_SoftwareFile.ResourceID = SMS_R_System.ResourceID
INNER JOIN SMS_MeteredFiles ON SMS_G_System_SoftwareFile.FileID = SMS_MeteredFiles.MeteredFileID
INNER JOIN SMS_MeteredProductRule ON SMS_MeteredProductRule.RuleID = SMS_MeteredFiles.RuleID
WHERE SMS_MeteredFiles.RuleID = 16777317 AND DateDiff(day, SMS_G_System_SoftwareFile.ModifiedDate, GetDate()) > 1 AND DateDiff(day, SMS_MeteredProductRule.LastUpdateTime, GetDate()) > 1 AND SMS_R_system.OperatingSystemNameAndVersion LIKE '%Workstation%' AND SMS_G_system_SoftwareFile.ResourceID NOT IN (SELECT DISTINCT SMS_MonthlyUsageSummary.ResourceID FROM SMS_MonthlyUsageSummary INNER JOIN SMS_MeteredFiles ON SMS_MonthlyUsageSummary.FileID = SMS_MeteredFile.MeteredFileID WHERE DateDiff(day, SMS_MonthlyUsageSummary.LastUsage, GetDate()) < 2 AND SMS_MeteredFiles.RuleID = 16777317)
This works fine for the purpose, but I want to incorporate device affinity along with it. And to do that, I want to add 'WHERE SMS_UserMachineRelationship.RelationActive = '1'' somewhere but I don't know where. All my guesses have resulted in invalid query.
This is for user collection. This was relatively easy to do for device deployments but I'm having hard time getting it to work for when a deployment is for user - and this is essential because the install deployment collection membership must first be deleted before the uninstall can be done.