This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

swis.query Finding Nodes With Custom Property Not Equal To A Given Value

I can use a swis.query to find nodes who have a custom property equal to a given value with something like this:

nodes = swis.query ('SELECT NodeID, Caption FROM Orion.Nodes WHERE Nodes.CustomProperties.DeviceType=@DeviceType', DeviceType=deviceType)['results']

Does anyone know how I can find nodes who have a custom property NOT equal to the given value?  I haven't been able to find a syntax that works for this.

Thanks.

  • Did you try Not Like in your Where statement ?
  • This worked in SWQL Studio for me for the custom property _city

    SELECT NodeID, Caption FROM Orion.Nodes WHERE Nodes.CustomProperties._city not like '%new york%'

  • Yes.  The syntax is accepted but returns no nodes.

    But while typing this reply I think I may know why.  In the case I'm working with the property is either populated with the given value or not populated at all yet.  The Not Like is probably not matching when the property is not populated.

    I'll be populating the other values tonight and will test it again tomorrow.

    Thanks.

  • Not Like Null is another option if they are not populated.

  • Thanks for the responses.  I populated the property with a different value on a test node and 'Not Like' is working the way I need it to.

  • Just to add a few more options.

    ### Option 1 -- Exclude 'Windows Server'
    
    SELECT n.Caption, n.IPAddress, n.NodeID, n.CustomProperties.DeviceType
    FROM Orion.Nodes AS n
    WHERE n.CustomProperties.DeviceType != 'Windows Server'
    
    ### Option 2 -- Exclude multiple values
    
    SELECT n.Caption, n.IPAddress, n.NodeID, n.CustomProperties.DeviceType
    FROM Orion.Nodes AS n
    WHERE n.CustomProperties.DeviceType NOT IN ( 'Windows Server', 'ESXi Server' )
    
    ### Option 2 -- Show only null values
    
    SELECT n.Caption, n.IPAddress, n.NodeID, n.CustomProperties.DeviceType
    FROM Orion.Nodes AS n
    WHERE n.CustomProperties.DeviceType IS NULL
    
    ### Option 4 -- A bit of each...
    
    SELECT n.Caption, n.IPAddress, n.NodeID, n.CustomProperties.DeviceType
    FROM Orion.Nodes AS n
    WHERE n.CustomProperties.DeviceType NOT IN ( 'Windows Server', 'ESXi Server' )
    OR n.CustomProperties.DeviceType IS NULL