Vishnu Dev
Vishnu Dev

Reputation: 45

How to check a string is in a specific format in SQL?

Need to find solution in SQL to check wether a string is in format

aCODE_1111111111

a - lower case letter
CODE - Uppercase letter.
Format start with aCODE_ and followed by 10 numbers. aCODE_ should be constant.

IF the input is in aCODE_1234567890 , result is true
IF the input is in aCODE_2256784558 , result is true
IF the input is in ACODE_1234567890 , result is false
IF the input is in aCODe_1234567890 , result is false
IF the input is in aCODE_123456789 , result is false

Upvotes: -1

Views: 3440

Answers (1)

Amira Bedhiafi
Amira Bedhiafi

Reputation: 1

Depending on your request, your query should be like this :

SELECT CASE
            WHEN t.solution SQL_Latin1_General_CP1_CS_AS 
                like 'aCODE[_][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
                   THEN 1
                   ELSE 0
           END as solution, *
    FROM yourtable

Upvotes: 3

Related Questions