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 8961577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:55:33+00:00 2026-06-15T15:55:33+00:00

We are currently running a script to dump Active Directory user information into a

  • 0

We are currently running a script to dump Active Directory user information into a database.

When we do the insert, we hash all the values into a hashcode column of type Varbinary(8000). This column is used to compare the hashes on the next run so that we only update the records that have changed.
At the moment, when the compare is done, it always comes back as different.

I’ve reduce the script to a basic example and still get the same issue.
(Enterprise person is the local table in my database where we keep our people information)

SELECT 
    SamAccountName
INTO
    #TmpEnterprisePerson    
FROM OPENQUERY(ADSI, 'SELECT SamAccountName
              FROM ''LDAP://MyLdapDirectory''
              WHERE SamAccountName = ''myAccount''')

    select HashBytes('MD5',COALESCE(EP.SamAccountName, '') ) as originalHash
        , HashBytes('MD5',COALESCE(T.SamAccountName, '')) as NewHash
        , EP.SamAccountName as originalName
        , T.SamAccountName as newName
        , '"' + EP.SamAccountName + '"' as originalName2
        , '"' + T.SamAccountName + '"' as newName2
        , CAST(COALESCE(EP.SamAccountName, '') AS VARbinary(max)) as oriBinaryName
        , CAST(COALESCE(T.SamAccountName, '') AS VARbinary(max)) as newBinaryName
        , len(ep.samaccountName) as originallength
        , len(T.samaccountName) as newLength
    FROM
        [dbo].[EnterprisePerson] AS EP
        INNER JOIN #TmpEnterprisePerson T ON T.SamAccountName = EP.SamAccountName
where ep.SamAccountName= 'myAccount'


drop table #TmpEnterprisePerson

The result is the following

OriginalHash = 0xEB4A732C6372E7F1558D4C95E34CE6FF
NewHash      = 0x82DDB9733D5A7532D1C2C734807BE756
OriginalName = MyAccount
NewName      = MyAccount //Same as originalName
OriginalNam2 = "MyAccount"
NewName2     = "MyAccount" //Same as originalName2
oriBinaryName= 0x4C415245415541
newBinaryName= 0x4C00410052004500410055004100
OriginalLen  = 7
NewLength    = 7

I’m not sure what I’m doing wrong when comparing the hashes or why they are coming out differently

  • 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-06-15T15:55:35+00:00Added an answer on June 15, 2026 at 3:55 pm

    I believe you have a datatype issue. Convert T.SamAccountName to varchar(N) – same type as what is stored in the database (or cast, if you prefer that over convert).

    SELECT 
        SamAccountName
    INTO
        #TmpEnterprisePerson    
    FROM OPENQUERY(ADSI, 'SELECT SamAccountName
                  FROM ''LDAP://MyLdapDirectory''
                  WHERE SamAccountName = ''myAccount''')
    
        select HashBytes('MD5',COALESCE(EP.SamAccountName, '') ) as originalHash
            , HashBytes('MD5', convert(varchar(50), COALESCE(T.SamAccountName), ''))) as NewHash
            , EP.SamAccountName as originalName
            , T.SamAccountName as newName
            , len(ep.samaccountName) as originallength
            , len(T.samaccountName) as newLength
        FROM
            [dbo].[EnterprisePerson] AS EP
            INNER JOIN #TmpEnterprisePerson T ON T.SamAccountName = EP.SamAccountName
    where ep.SamAccountName= 'myAccount'
    
    
    drop table #TmpEnterprisePerson
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running a PHP script that queries the database and then sends
I have this script that I am currently running that works great for all
Ok, so I'm currently running this script to remove all the excess spaces, linebreaks,
I'm currently writing a ToDo-Script for a project i have running. Now there is
I am running a server with cherrypy and python script. Currently, there is a
I am running a server with cherrypy and python script. Currently, there is a
I am currently running into an issue trying to create delegates from MethodInfo .
I'm currently running into trouble configuring MAMP 2 to use SSL with multiple virtual
I'm currently running these lines in a PHP script: foreach ($list as $route) {
We are currently running an ajax auto complete script through mySQL, as such: <?php

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.