sccmwql

Simple WQL query issue


The full query:

select 
  SMS_G_System_COMPUTER_SYSTEM.Name,
  SMS_G_System_COMPUTER_SYSTEM.Model,
  SMS_R_System.OperatingSystemNameandVersion,
  SMS_R_System.Build,
  SMS_R_User.UniqueUserName

from 
  SMS_R_System
    inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId
    INNER JOIN SMS_UserMachineRelationship ON SMS_UserMachineRelationship.ResourceId = SMS_R_System.ResourceId
    INNER JOIN SMS_R_User ON SMS_UserMachineRelationship.UniqueUserName = SMS_R_User.UniqueUserName

WHERE 
  SMS_UserMachineRelationship.Types = 1
  SMS_R_User.UniqueUserName LIKE "%,%"

order by 
  SMS_G_System_COMPUTER_SYSTEM.Name

The issue I am here to discuss and need assistance with is jut this line:

SMS_R_User.UniqueUserName LIKE "%,%"

No matter what I try here after the LIKE operator, it is just always a syntax error. Have no idea what is wrong with it, it matches all the examples online, and previous queries I have written.

Any ideas?


Solution

  • You have a syntax error. You're missing an AND between the two conditions in your WHERE clause. This is standard SQL syntax, so it's nothing special related to WQL.

    It should be

    WHERE 
      SMS_UserMachineRelationship.Types = 1 AND
      SMS_R_User.UniqueUserName LIKE "%,%"