SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL ADSI Query limitation


SQL ADSI Query limitation

Author
Message
Tracy Nolan
Tracy Nolan
SSC-Enthusiastic
SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)

Group: General Forum Members
Points: 113 Visits: 155
Excellent, works like a charm!!
christoph.hackstein 38861
christoph.hackstein 38861
Valued Member
Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)

Group: General Forum Members
Points: 53 Visits: 1
What about http://www.selfadsi.de/search.htm#MaxPageSizeADS
kerry.smith 57835
kerry.smith 57835
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 3
Brian ODwyer - Thursday, February 9, 2012 2:54 PM
Definite 255 char limit. See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65584I used the function to get around and loop throughdeclare @Apptemp3 table (BSamName varchar(255), BDisplayName varchar(255), BPhone varchar(100), BEMail varchar(255), BFirstName varchar(100), BLastName varchar(100))DECLARE @sChar char(1)declare @body varchar(8000)DECLARE @nAsciiValue smallintSELECT @nAsciiValue = 65WHILE @nAsciiValue < 91 BEGIN SELECT @sChar= CHAR(@nAsciiValue)SET @body = (select dbo.fnSprintf('SELECT sAMAccountName, displayName, mail, telephoneNumber, sn, givenName FROM OPENQUERY( ADSI, ''SELECT displayName, sAMAccountName, mail, telephoneNumber, sn, givenName FROM ''''LDAP://dc=cchcs,dc=ldap''''WHERE objectCategory = ''''Person'''' AND SAMAccountName = ''''%s*'''''' )', @SChar +'*', default)) INSERT @Apptemp3 EXEC( @body) SELECT @nAsciiValue = @nAsciiValue + 1 ENDSelect ISNULL(Upper(BSamName),'NoSamID'),ISNULL(BDisplayName,'NoDName'),ISNULL(BPhone,'NoPhone'),ISNULL(BEMail,'Nomail'),ISNULL(BFirstName,'NoFname'),ISNULL(BLastName,'NoLname') from @Apptemp3order by BSamName

The above example was great but I ran into an issue where there were more than 1000 's' names and even more than 1000 service accounts with 's.*' naming format.

While not elegant my script below loops through the different parts of the alphabet and handles s. Hope this helps somebody else.

--Hitting row limitations at 's' > chokes on services

DROP TABLE #tmpADUsers;

CREATE TABLE #tmpADUsers
(
employeeId VARCHAR(10) NULL,
SAMAccountName VARCHAR(255) NOT NULL,
givenname VARCHAR(255) NULL,
sn VARCHAR(255) NULL,
email VARCHAR(255) NULL,
CN VARCHAR(255) NULL
);

GO
-- loop through the alphabet from A-R

DECLARE @cmdstr VARCHAR(255);
DECLARE @nAsciiValue SMALLINT;
DECLARE @sChar CHAR(1);

SELECT @nAsciiValue = 65;

WHILE @nAsciiValue < 83
BEGIN

SELECT @sChar = CHAR(@nAsciiValue);

EXEC master..xp_sprintf @cmdstr OUTPUT,
'SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM OPENQUERY( ADSI, ''SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM ''''LDAP://DC=corp,DC=symetra,DC=com''''WHERE objectCategory = ''''Person'''' AND SAMAccountName = ''''%s*'''''' )',
@sChar;

INSERT #tmpADUsers
EXEC (@cmdstr);

SELECT @nAsciiValue = @nAsciiValue + 1;
END;


-- loop through the alphabet from T-Z
GO
DECLARE @cmdstr VARCHAR(255);
DECLARE @nAsciiValue SMALLINT;
DECLARE @sChar CHAR(1);

SELECT @nAsciiValue = 84;

WHILE @nAsciiValue < 91
BEGIN

SELECT @sChar = CHAR(@nAsciiValue);

EXEC master..xp_sprintf @cmdstr OUTPUT,
'SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM OPENQUERY( ADSI, ''SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM ''''LDAP://DC=corp,DC=symetra,DC=com''''WHERE objectCategory = ''''Person'''' AND SAMAccountName = ''''%s*'''''' )',
@sChar;

INSERT #tmpADUsers
EXEC (@cmdstr);

SELECT @nAsciiValue = @nAsciiValue + 1;
END;




-- pull in s followed by an alpha
GO
DECLARE @cmdstr VARCHAR(255);
DECLARE @nAsciiValue SMALLINT;
DECLARE @sChar CHAR(1);


SELECT @nAsciiValue = 84;

WHILE @nAsciiValue < 91
BEGIN

SELECT @sChar = CHAR(@nAsciiValue);

EXEC master..xp_sprintf @cmdstr OUTPUT,
'SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM OPENQUERY( ADSI, ''SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM ''''LDAP://DC=corp,DC=symetra,DC=com''''WHERE objectCategory = ''''Person'''' AND SAMAccountName = ''''s%s*'''''' )',
@sChar;

INSERT #tmpADUsers
EXEC (@cmdstr);

SELECT @nAsciiValue = @nAsciiValue + 1;
END;

GO
--this pulls in s with periods as the 2nd character
DECLARE @cmdstr VARCHAR(255);
DECLARE @nAsciiValue SMALLINT;
DECLARE @sChar CHAR(1);

SELECT @nAsciiValue = 65;

WHILE @nAsciiValue < 91
BEGIN

SELECT @sChar = CHAR(@nAsciiValue);

EXEC master..xp_sprintf @cmdstr OUTPUT,
'SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM OPENQUERY( ADSI, ''SELECT employeeId, SAMAccountName, givenname, sn, Mail, CN
FROM ''''LDAP://DC=corp,DC=symetra,DC=com'''' WHERE objectCategory = ''''Person'''' AND SAMAccountName = ''''s.%s*'''''' )',
@sChar;

INSERT #tmpADUsers
EXEC (@cmdstr);

SELECT @nAsciiValue = @nAsciiValue + 1;
END;



SELECT *
FROM #tmpADUsers
ORDER BY SAMAccountName;

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search