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.
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