是否存在LDAP查询的GROUP BY语法等效项。我正在尝试返回特定公司每个部门的人员和职称列表。我的代码是:
<%@ Language="VBScript"%>
<% response.Buffer = True
dim ADUser 'Holds the OU
dim RecordList 'Holds the RecordList object
%>
<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<!--#include virtual="//includes/functions.asp"-->
<!--#include virtual="//includes/display.asp"-->
<h1>Organisational Structure</h1>
<div class="commandspace">
<p class="infotext">The org structure can be viewed with or without staff, indented or left justified.</p>
</div>
<%
ADUser = "LDAP://OU=Staff,OU=Users,DC=company,DC=internal"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "EXAMPLE\User"
objCon.Properties("Password") = "PaSsWoRd"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
objCom.CommandText ="select company, department, givenName, sn, title, telephoneNumber FROM '"& ADUser &"' where company ='*' GROUP BY company"
Set objRS = objCom.Execute
RecordList = objRS.GetRows()
' Loop over returned recordset and output HTML
for i = 0 to uBound(RecordList, 2)
u = i + 1
if RecordList(5,i) <> RecordList(5,u) then
Response.Write "<div class='Structure_Item_1'>" & RecordList(5,i) & "</div>" & vbCrLf
end if
if RecordList(4,i) <> RecordList(4,u) then
Response.Write "<div class='Structure_Item_2'>" & RecordList(4,i) & "</div>" & vbCrLf
end if
Response.Write "<div class='Structure_Item_3'>" & RecordList(3,i) & " " & RecordList(2,i) & "</div>" &vbCrLf
next
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
</body>
</html>
我得到了
Provider error '80040e14'
One or more errors occurred during processing of command.
/pagelets/structure.asp, line 25
当我这样做的时候有同等的功能吗?
答案 0 :(得分:0)
我不认为你的问题是LDAP在某种程度上不支持GROUP BY;它的查询不是有效的GROUP BY查询。查询返回的每一列必须 分组的一部分或聚合值。您不能返回既不是。
的列dim sql
sql = "SELECT Company, Department, Count(*) AS nUsers FROM '" & adUser & "'"
sql = sql & " WHERE company = '*' GROUP BY Company, Department"
sql = sql & " ORDER BY Company, Department"
(WHERE company = '*'
的目的是什么?)
所有人都说,我不认为你需要分组;你只需要排序。
sql = "SELECT company, department, givenName, sn, title, telephoneNumber"
sql = sql & " FROM '" & adUser & "' WHERE company Is Not NULL"
sql = sql & " ORDER BY company, department, givenName"