Friday, March 21, 2008

Computers without specific file

Normally you need to check computers where specific file is present. What to do if you need to find out computers without specific file. Simple query with just NOT IN command will not work. You need to create the query in this way:

SELECT DISTINCT
sys.Netbios_Name0

FROM v_R_System sys
INNER JOIN v_GS_SoftwareFile sf
ON sys.ResourceID = sf.ResourceID

WHERE sys.ResourceID NOT IN
(
SELECT DISTINCT sys.ResourceID
FROM v_R_System sys
INNER JOIN v_GS_SoftwareFile sf
ON sys.ResourceID = sf.ResourceID

WHERE sf.FileName = 'AcroRd32.exe'
)

ORDER BY 1

The key for the success is NOT IN command. It will select (from all computers) the ones which are not in select of computers containing requested software.