错误的SQL查询?

时间:2013-05-17 10:33:28

标签: sql sql-server sql-server-2008

我现在正在为sccm 2012数据库创建一个SQL查询,并希望查看所有客户端安装的程序。

但是在请求之后所有客户都有相同的程序。

下面是代码:

SELECT Computer_System_DATA.Name00,
       Computer_System_DATA.UserName00,
       installed_software_data.productname00,
       installed_software_data.publisher00
FROM Computer_System_DATA, installed_software_data
WHERE installed_software_data.publisher00 NOT LIKE N'%microsoft%' and 
      installed_software_data.publisher00 NOT LIKE N'%Intel%' and  
      installed_software_data.publisher00 NOT LIKE N'%nvidia%' and 
      installed_software_data.publisher00 NOT LIKE N'%vmware%'and 
      installed_software_data.publisher00 NOT LIKE N'%symantec%'and 
      installed_software_data.publisher00 NOT LIKE N'%hewlett-packard%'and
      installed_software_data.publisher00 NOT LIKE N'%hp%'and
      installed_software_data.productname00 NOT LIKE N'%driver%' and 
      installed_software_data.productname00 NOT LIKE N'%install%' and 
      installed_software_data.productname00 NOT LIKE N'%update%' and 
      installed_software_data.productname00 NOT LIKE N'%treiber%' and 
      installed_software_data.productname00 NOT LIKE N'%microsoft%' and 
      installed_software_data.productname00 NOT LIKE N'%hp%' and 
      installed_software_data.productname00 NOT LIKE N'%ghost%' and 
      installed_software_data.productname00 NOT LIKE N'%flash%'and 
      installed_software_data.productname00 NOT LIKE N'%hotfix%' and 
      installed_software_data.productname00 NOT LIKE N'%patch%' and 
      installed_software_data.productname00 NOT LIKE N'%device%' and 
      installed_software_data.productname00 NOT LIKE N'%runtime%' and 
      installed_software_data.productname00 NOT LIKE N'%java%' and 
      installed_software_data.productname00 NOT LIKE N'%player%' and 
      installed_software_data.productname00 NOT LIKE N'%ati%' and 
      installed_software_data.productname00 NOT LIKE N'%broadcom%'and 
      installed_software_data.productname00 NOT LIKE N'%canon%' and 
      installed_software_data.productname00 NOT LIKE N'%dell%' and 
      installed_software_data.productname00 NOT LIKE N'%divx%' and 
      installed_software_data.productname00 NOT LIKE N'%epson%' and 
      installed_software_data.productname00 NOT LIKE N'%veritas%' and 
      installed_software_data.productname00 NOT LIKE N'%defender%' and 
      installed_software_data.productname00 NOT LIKE N'%AFPL%' and 
      installed_software_data.productname00 NOT LIKE N'%web%' and 
      installed_software_data.productname00 NOT LIKE N'%xml%' and 
      installed_software_data.productname00 NOT LIKE N'%framework%' and 
      installed_software_data.productname00 NOT LIKE N'%soundmax%' and 
      installed_software_data.productname00 NOT LIKE N'%silverlight%' and 
      installed_software_data.productname00 NOT LIKE N'%buffer%' and 
      installed_software_data.productname00 NOT LIKE N'%Crazyflie Client%'

2 个答案:

答案 0 :(得分:2)

您正在FROM子句中进行交叉连接。你可能需要一个带有正确ON子句的INNER JOIN。类似的东西:

FROM   Computer_System_Data INNER JOIN
       Installed_SoftWare_Data 
         ON Computer_System_Data.ComputerID = Installed_SoftWare_Data.ComputerID

答案 1 :(得分:1)

试试这个 -

 SELECT  c.Name00 ,
            c.UserName00 ,
            d.productname00 ,
            d.publisher00
    FROM dbo.Computer_System_DATA c
    CROSS JOIN dbo.installed_software_data d --ON c.ComputerID = d.ComputerID
    WHERE NOT EXISTS (
            SELECT 1
            FROM (
                VALUES 
                (N'microsoft'),(N'Intel'),
                (N'Intel'),(N'nvidia'),
                (N'vmware'),(N'symantec'),
                (N'hewlett-packard'),(N'hp')
            ) AS x(filter)
            WHERE d.publisher00 LIKE N'%' + filter + N'%'
        )
    AND NOT EXISTS (
            SELECT 1
            FROM (
                VALUES 
                    (N'driver'),(N'install'),
                    (N'update'),(N'treiber'),
                    (N'microsoft'),(N'hp'),
                    (N'ghost'),(N'flash'),
                    (N'hotfix'),(N'patch'),
                    (N'device'),(N'runtime'),
                    (N'java'),(N'player'),
                    (N'ati'),(N'broadcom'),
                    (N'canon'),(N'dell'),
                    (N'divx'),(N'epson'),
                    (N'veritas'),(N'defender'),
                    (N'AFPL'),(N'web'),
                    (N'xml'),(N'framework'),
                    (N'soundmax'),(N'silverlight'),
                    (N'buffer'),(N'Crazyflie Client')
            ) AS x(filter)
            WHERE d.productname00 LIKE N'%' + filter + N'%'
        )