Ayrton Senna
Ayrton Senna

Reputation: 3855

TSQL Simple Regex Matching

I need to check if a variable is a value 10.00 through 10.09. How can I do this by regex ?

IF SomeRegExFunction(@var, '10.0*')
    print 'It worked'

Is there some way to do this?

Thanks

Upvotes: 0

Views: 1396

Answers (3)

Taryn
Taryn

Reputation: 247880

You can use the following:

declare @var as varchar(10)
set @var = '11.07'

if @var like '10.0[0-9]'
    print 'It worked'
else
    print 'not a match'

See SQL Fiddle with Demo

Upvotes: 2

Andomar
Andomar

Reputation: 238296

SQL Server's like as a simple expression syntax:

if @var like '10.0[0-9]' or @var = '10.0'
    print 'Hello World!'

Upvotes: 1

Mr T.
Mr T.

Reputation: 4518

How about PATINDEX. I think that you are looking for something like this.

Upvotes: 0

Related Questions