1

I have two types of patterns:

'nnn-nn-nnnn'

and

'nn-nnnnnnn'

where n = always a number.

how do I flag the first as 1 and second as 2? having a hard time figuring out how to do the expression. thank you.

1 Answer 1

2

Well, you can use like, but if you want to check the complete pattern (and you probably should) it's going to be messy:

 SELECT CASE 
        WHEN pattern LIKE '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]' THEN 1
        WHEN pattern LIKE '[0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]' THEN 2
        END As patternType

You could, if you are only ever going to have only these two patterns, simply use charindex:

SELECT CASE 
       WHEN charindex('-', pattern) = 4 THEN 1
       ELSE 2
       END As patternType
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.