[quoted text, click to view] On 22 Mar 2004 22:16:22 -0800, Mike W. wrote:
>I'm trying to pull a report from my SMS database that will list a
>yes/no type answer for each server, as to whether a file exists on
>that system. There are basically 3 tables involved:
>
>SoftwareInventory, which contains Columns (ClientID and FileID)
>System_DATA, which joins to SoftwareInventory on ClientID and
>SoftwareFile, which joins to SoftwareInventory on FileID.
>
>Each system will have one row in System_Data which will join to many
>in SoftwareInventory, which will link to one row in SoftwareFile, thus
>making the coorelation.
>
>If I just wanted a list of systems with the file, the syntax might
>look like (I apolgize for any stylistic errors, as I'm not a guru):
>
>SELECT System_Data.Name0,SoftwareFile.FileName
>FROM System_Data
>INNER JOIN SoftwareInventory on
>System_Data.MachineID=SoftwareInventory.ClientID
>INNER JOIN SoftwareFile on
>SoftwareInventory.FileID-SoftwareFile.FileID
>WHERE System_DATA.Name0 like '%SERVER% and SoftwareFile.FileName like
>'foo.exe'
>
>In order to get the yes/no type response, I though about using a CASE
>in the select, like so:
>
>SELECT System_DATA.Name0, CASE WHEN SoftwareFile.FileName like
>'foo.exe' THEN 'YES' ElSE 'NO'
>
>Which, and it suddenly seems obvious, returns a YES/NO for every file
>on the system.
>
>I guess what I'm looking for is for it to check SoftwareInventory for
>the correct FileID that's associated with the particular machine ID.
>If it finds it, then YES, else NO.
>
>Is this something I should be using a subselect for? I'm not really
>sure how to proceed with this.
>
>Thanks,
>
>Mike
First, you should replace "LIKE 'foo.exe'" with "= 'foo.exe'". Use
LIKE only for wildcard searches.
What you want can be achieved by:
IF EXISTS
(SELECT System_Data.Name0,SoftwareFile.FileName
FROM System_Data
INNER JOIN SoftwareInventory on
System_Data.MachineID=SoftwareInventory.ClientID
INNER JOIN SoftwareFile on
SoftwareInventory.FileID-SoftwareFile.FileID
WHERE System_DATA.Name0 like '%SERVER%
and SoftwareFile.FileName = 'foo.exe')
PRINT 'YES'
ELSE PRINT 'NO'
Or, if you must have it in a select statement:
SELECT CASE
WHEN EXISTS
(SELECT System_Data.Name0,SoftwareFile.FileName
FROM System_Data
INNER JOIN SoftwareInventory on
System_Data.MachineID=SoftwareInventory.ClientID
INNER JOIN SoftwareFile on
SoftwareInventory.FileID-SoftwareFile.FileID
WHERE System_DATA.Name0 like '%SERVER%
and SoftwareFile.FileName = 'foo.exe')
THEN 'YES'
ELSE 'NO'
END
Best, Hugo
--