根据结果使用if语句在查询中进行查询

qgzx9mmu  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(297)

所以我有一个奇怪的问题,关于我创建的ssrs报告。

SELECT        rs.Name0, rs.User_Name0, rs.AD_Site_Name0, rs.User_Domain0, rs.Full_Domain_Name0, rs.Operating_System_Name_and0, eps.Active, eps.EpInstalled, eps.EpProtected, 
                         dbo.v_GS_AntimalwareHealthStatus.Enabled, dbo.v_GS_AntimalwareHealthStatus.Version, dbo.v_GS_AntimalwareHealthStatus.AntivirusEnabled, dbo.v_GS_AntimalwareHealthStatus.AntispywareEnabled, 
                         dbo.v_GS_AntimalwareHealthStatus.EngineVersion, eps.EpToBeInstalled,
                             (SELECT        rua.ProductName0
                               FROM            dbo.v_GS_CCM_RECENTLY_USED AS rua
                               WHERE        (rs.ressourceID = rua.ressourceID)) AS Kaspersky
FROM            dbo.v_R_System AS rs INNER JOIN
                         dbo.v_EndpointProtectionStatus AS eps ON rs.ResourceID = eps.ResourceID INNER JOIN
                         dbo.v_GS_AntimalwareHealthStatus ON rs.ResourceID = dbo.v_GS_AntimalwareHealthStatus.ResourceID INNER JOIN
                         dbo.v_GS_CCM_RECENTLY_USED_APPS AS rua ON rs.ResourceID = rua.ResourceID

为了方便起见,我正在尝试选择是否在机器上启用了endpoint,以及是否也存在kaspersky。但我想不通!我不知道如何管理它,因为此查询:

(SELECT        rua.ProductName0
                               FROM            dbo.v_GS_CCM_RECENTLY_USED AS rua
                               WHERE        (rs.ressourceID = rua.ressourceID)) AS Kaspersky

它返回多行(因为它们是安装在目标计算机集合上的卡巴斯基的多个版本)。但我所需要的是,如果它返回一些东西(因为这意味着卡巴斯基在机器上存在),然后返回“true”或“it's installed”之类的东西。
我已经有一段时间没有做sql查询了,所以如果你能帮我的话,请提前谢谢你。

icnyk63a

icnyk63a1#

所以我终于找到了答案,答案如下:

SELECT      rs.Name0, 
            rs.User_Name0, 
            rs.AD_Site_Name0, 
            rs.User_Domain0, 
            rs.Full_Domain_Name0, 
            rs.Operating_System_Name_and0, 
            eps.Active, 
            eps.EpInstalled, 
            eps.EpProtected, 
            eps.EpToBeInstalled,

            Case WHEN EXISTS (SELECT rua.ProductName0 FROM v_GS_CCM_RECENTLY_USED_APPS AS rua WHERE rs.resourceID = rua.resourceID AND rua.ProductName0 LIKE '%Kaspersky%') 
            THEN 'Yes'
            ELSE 'No'
            END AS "Is Kaspersky installed?"

FROM            v_R_System AS rs INNER JOIN
                v_EndpointProtectionStatus AS eps ON rs.ResourceID = eps.ResourceID

相关问题