简体   繁体   English

SCCM2012 SQL查询有错误

[英]SCCM2012 SQL Query has an error

I am creating an SQL query for my SCCM collection but I get that there is an error. 我正在为我的SCCM集合创建一个SQL查询,但是我得到一个错误。 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' ? 假设您没有拼写任何列名,那么我看到的唯一会抛出错误的事情就是"Domain\\\\GroupName"应该是'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 ?? 消息207,第16级,状态1,行?? Invalid column name 'Domain\\GroupName'. 无效的列名“ Domain \\ GroupName”。

Also, the subquery in the where clause looks unnecessary, this query should be equivalent (if I'm not misreading it): 另外,where子句中的子查询看起来不必要,该查询应该是等效的(如果我没有误读的话):

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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