Almelyan
Almelyan

Reputation: 37

Special Pattern by SQL LIKE clause

Need special pattern for finding values that are 13 length chars, first of 12 are numbers for example 119910023525P There are 2 Pattern :

LIKE '____________P' 

or

LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]P'

Need something as '[0-9]{12}P' It's Possible In MS-SQL Server ?

Upvotes: 1

Views: 77

Answers (3)

Gordon Linoff
Gordon Linoff

Reputation: 1271111

You could use this logic:

(x like '%P' and x not like '%[^0-9]%P' and len(x) = 13)

But that is about the same amount of typing as just manually replicated [0-9] 12 times.

Upvotes: 0

Martin Smith
Martin Smith

Reputation: 453910

There are no quantifiers in the TSQL pattern syntax.

You can use

LIKE REPLICATE('[0-9]',12) + 'P'

Upvotes: 2

Johannes Schidlowski
Johannes Schidlowski

Reputation: 112

Maybe the REGEXP() function will help you with this task.

Upvotes: -1

Related Questions