简体   繁体   中英

SCCM2012 SQL Query has an error

I am creating an SQL query for my SCCM collection but I get that there is an error. It doesn't tell me what the error is and the rule looks ok for me.

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, SMS_R_User.UniqueUserName
FROM SMS_R_System
JOIN SMS_UserMachineRelationship ON SMS_R_System.Name=SMS_UserMachineRelationship.MachineResourceName
JOIN SMS_R_User ON SMS_UserMachineRelationship.UniqueUserName=SMS_R_User.UniqueUserName
Where SMS_R_User.UniqueUserName in (select UniqueUserName from SMS_R_User where UserGroupName = "Domain\\GroupName")

Assuming that you haven't misspelled any column names the only thing that I can see that would throw an error is that maybe "Domain\\\\GroupName" should be 'Domain\\\\GroupName' ? Double-quotes are normally used as quoted identifiers for objects while single-quotes denote string literals.

With the double quotes you would probably get an error like:

Msg 207, Level 16, State 1, Line ?? Invalid column name 'Domain\\GroupName'.

Also, the subquery in the where clause looks unnecessary, this query should be equivalent (if I'm not misreading it):

SELECT 
    S.ResourceID,
    S.ResourceType,
    S.Name,
    S.SMSUniqueIdentifier,
    S.ResourceDomainORWorkgroup,
    S.Client, 
    U.UniqueUserName
FROM SMS_R_System S
JOIN SMS_UserMachineRelationship UMR ON S.Name = UMR.MachineResourceName
JOIN SMS_R_User U ON UMR.UniqueUserName = U.UniqueUserName
WHERE U.UserGroupName = 'Domain\\GroupName'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM