wildcharacter search in a where clause

Hi tere,
what's the best practices to include this where clause in my stored procedure
and SUBSTRING(R.glrf_full_acct,15, 3)not like '81.[0-9][0-9][0-9][0-9].[0-9][0-9][0-9][0-9][0-9].207%,'

Open in new window

I'm searching specifically for numbers that starts with 81 and follow by any number in any of those position but after the 15 character has a 207
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
For SUBSTRING, the second value is the starting position and the third is the length.

Did you mean to do start in byte 3 and go at least 17 bytes, like this?:

and SUBSTRING(R.glrf_full_acct, 3, 18) not like '81.[0-9][0-9][0-9][0-9].[0-9][0-9][0-9][0-9][0-9].207%,'

If the value does start in byte 15, you need to change length to 17+:

and SUBSTRING(R.glrf_full_acct, 15, 18) not like '81.[0-9][0-9][0-9][0-9].[0-9][0-9][0-9][0-9][0-9].207%,'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
COHFLAuthor Commented:
That is true but I need to make sure the first two are 81. I do happen to have 207 with a different starting set of numbers
Vitor MontalvãoMSSQL Senior EngineerCommented:
How about this one?
WHERE ISNUMERIC(R.glrf_full_acct)=1 AND LEFT(R.glrf_full_acct,2)='81' AND SUBSTRING(R.glrf_full_acct,15, 3) = '207'

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.