Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL LIKE regular expression

I'm trying to select only entries in the following format from a varchar field.

[Any number of zeros][a hyphen or not][any number of numbers]

Some samples of what I want would be...

000000000007975
000000000-58628
123421423890347

But not:

00000--18945489
00000000000012B

SELECT Field<br>
FROM table<br>
WHERE Field LIKE ???
like image 532
Bolt_Head Avatar asked Sep 10 '26 22:09

Bolt_Head


1 Answers

T-SQL does not support regular expressions. You could look into the CLR to add this.

http://www.simple-talk.com/sql/t-sql-programming/clr-assembly-regex-functions-for-sql-server-by-example/

like image 178
Fabian Avatar answered Sep 13 '26 09:09

Fabian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!