Jump to content


Sign in to follow this  
Harrison Groover

Query Based Collections - combining two queries

Recommended Posts

I have a working query (Membership Rule) that gathers computers into a collection based on computer name.

 

I also have a working query that gathers by OS (in this example we will use Windows 7).

 

I have been trying to get the two combined into one query (basically an "and" statement instead of creating two separate membership rules, which apparently is an "or" statement).

 

I readily admit that building queries is not my strongpoint, and I don't even know if this is the proper way to go about it, but I have been tinkering with it quite a bit.

 

Here are the two queries...I know that both of them work individually, but I keep getting syntax errors when I try to combine them.

 

 

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_R_System.OperatingSystemNameandVersion like "%Workstation 6.1%" or SMS_R_System.OperatingSystemNameandVersion like "%Windows 7%" and SMS_G_System_COMPUTER_SYSTEM.SystemType = "x64-based PC"

 

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.NetbiosName like "Example"

 

Is there a way to combine these two statements into one? Any help would be very much appreciated!

Share this post


Link to post
Share on other sites


That shouldn't be to difficult as they are both using the same classes. I think it could be something like this (haven't tested it):

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.SystemType = "x64-based PC" and SMS_R_System.NetbiosName like "Example" and (SMS_R_System.OperatingSystemNameandVersion like "%Workstation 6.1%" or SMS_R_System.OperatingSystemNameandVersion like "%Windows 7%")

 

As you might also notice I've changed the operating system check. This is to assure that both options are valid, although I think that the second option doesn't even exist.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...