Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:55:58+00:00 2026-05-27T01:55:58+00:00

I’m wondering if the current process I’m using to update a table of user’s

  • 0

I’m wondering if the current process I’m using to update a table of user’s (tblUsers) Windows ID’s (NTID) is a good method. I’m wondering because LDAP will only return 1000 rows I believe, so that prevents me from just doing it all in one query.

tlbUsers has about 160,000 rows. I’m querying LDAP to update the NTID of each record in tblUsers. I’m using a linked server to ADSI to view LDAP data. My process uses two stored procedures, one for getting a WindowsID from LDAP (LdapPackage.GetUserNTID), another for updating the rows in tblUsers (LdapPackage.UpdateUserNTID).

The code below works for updating the table, however, it’s pretty slow. It would seem to me this isn’t the best way of doing it, that if I wanted to do a batch update like this from LDAP, there should be a simpler way than updating a record at a time.

This previous post gave an interesting example using UNION’s to get around the 1000 record limit, but it only works if each query returns less than 1000 records, which at a large company would probably require lots of UNIONS… at least that’s my initial take on it.

Querying Active Directory from SQL Server 2005

Thanks in advance guys!!!

<code>
CREATE PROCEDURE LdapPackage.GetUserNTID
(
    @EmployeeID INT,
    @OutNTID VARCHAR(20) OUTPUT

)
AS
BEGIN

DECLARE @SQLString NVARCHAR(MAX)
DECLARE @ParmDefinition NVARCHAR(MAX)
DECLARE @LdapFilter NVARCHAR(100)
--DECLARE @NTID   VARCHAR(20)

SET @LdapFilter = 'employeeNumber = ' + CAST(@EmployeeID AS NVARCHAR(20))

SET @SQLString = 'SELECT DISTINCT @pNTID = samAccountName
    FROM  OPENQUERY(LDAP, 
        ''select samAccountName, Mail
        from ''''GC://domain.company.com''''
        where objectClass=''''user'''' AND objectCategory=''''person'''' and ' + @LdapFilter + ''')
    WHERE Mail IS NOT NULL'

SET @ParmDefinition = N'@pNTID varchar(20) OUTPUT'

EXECUTE sp_executesql
@SQLString,
@ParmDefinition,
@pNTID=@OutNTID OUTPUT

--SELECT NTID = @OutNTID

END
</code>

<code>
CREATE PROCEDURE LdapPackage.UpdateUserNTID
AS
BEGIN

    DECLARE @EmployeeID     AS INT
    DECLARE @NTID       AS VARCHAR(20)
    DECLARE @RowCount   AS INT
    DECLARE @SQLString  AS NVARCHAR(MAX)
    DECLARE @ParmDefinition AS NVARCHAR(200)

    SET @RowCount = 1
    DECLARE Persons CURSOR 
        FOR SELECT DISTINCT EmployeeID FROM tblUsers

    OPEN Persons
    FETCH NEXT FROM Persons INTO @EmployeeID
    WHILE @@FETCH_STATUS = 0
    BEGIN
        --GET NTID
        SET @SQLString =N'EXEC LdapPackage.GetUserNTID @pEmployeeID, @pNTID OUTPUT'

        SET @ParmDefinition =N'@pEmployeeID INT, @pNTID VARCHAR(20) OUTPUT'

        EXECUTE sp_executesql
            @SQLString,
            @ParmDefinition,
            @pEmployeeID=@EmployeeID,
            @pNTID=@NTID OUTPUT
        --UPDATE NTID
        /*PRINT 'RowCount = ' + CAST(@RowCount AS VARCHAR(10))
        PRINT 'EmployeeID   = ' + CAST(@EmployeeID AS VARCHAR(20))
        PRINT 'NTID     = ' + @NTID
        PRINT '-----------------------------'*/
        UPDATE tblUsers
        SET NTID = @NTID
        WHERE EmployeeID = @EmployeeID

        SET @RowCount = @RowCount + 1
        FETCH NEXT FROM Persons INTO @EmployeeID
    END
    CLOSE Persons
    DEALLOCATE Persons
END
</code>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:55:59+00:00Added an answer on May 27, 2026 at 1:55 am

    my solution here was to have my that linked servers record limit to LDAP increased by the system admin. I would have preferred to have identified some sort of SQL Server interface like Oracle appears to have… so maybe I’ll get to that in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.