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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:28:16+00:00 2026-05-31T00:28:16+00:00

Question: I need to COMPARE if a string is a MD5 Hash in SQL.

  • 0

Question:

I need to COMPARE if a string is a MD5 Hash in SQL.

I found this PHP-function:

function isValidMd5($md5)
{
    return !empty($md5) && preg_match('/^[a-f0-9]{32}$/', $md5);
}

Since SQL lacks the {32} syntax, I just duplicate [a-f0-9] 32 times:

IF '200ceb26807d6bf99fd6f4f0d1ca54d4' LIKE '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]' 
BEGIN
    PRINT 'YES'
END
ELSE
BEGIN
    PRINT 'NO'
END 

However, to avoid a possible collision with a username consisting of 32 [a-f], however unlikely, I want to do the like comparison uppercase.

But if for testing purposes I do:

IF 'E' COLLATE Latin1_General_CS_AS  LIKE ('[a-f0-9]' COLLATE Latin1_General_CS_AS )
BEGIN
    PRINT 'yes'
END
ELSE
BEGIN
    PRINT 'no'
END 

I get yes, and not no.
However COLLATE Latin1_General_CS_AS should make it case-sensitive…

How can a make the LIKE in this IF case-sensitive ?

  • 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-31T00:28:17+00:00Added an answer on May 31, 2026 at 12:28 am

    Better to invert the check and make it simpler to maintain by checking for any single thing that will make it fail. This means you don’t have to repeat [0-9a-f] 32 times in the code.

    IF LEN(@myValue) <> 32 OR LOWER(@myValue) LIKE '%[^0-9a-f]%' 
    BEGIN
       -- No it isn't
    END ELSE BEGIN
       -- Yes it is
    END
    

    i.e., if it’s not 32 chars OR it contains a character outside the hexadecimal set then it fails.

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

Sidebar

Related Questions

This is hopefully a softball syntax question: I need to call a method with
For reasons that are irrelevant to this question I'll need to run several SQLite
All I need is to compare dates represented by string values in the format
Heyhoo, now i need to compare a String like [INTENSITY] to $line. ATM i
Hi, I have a linq to sql question like this : tmpAdList1 = (from
So, this question is similar to what I need, but the answers there don't
Question: I need a way to automate routine tests that tell me if my
Question: I need to call a C# dll from a C++ executable. I use
An inexperienced question: I need to store about 10 unknown-length text fields per record
Quick (and hopefully easy) question: I need to trigger a download of a PDF

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.