Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Matches a number pattern help

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-10-27 : 17:26:48
I need a Sql like me syntax that matches pattern ########-#####-####-####-###########

# represents any number

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-27 : 17:42:08
Not sure if there's a shorter way, but here goes:

select *
from table1
where column1 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][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-10-27 : 17:49:38
K what about the - between the numbers
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-27 : 17:56:22
The dashes are already in there. Might be hard to spot due to the dash between 0 and 9, but the extra dashes between the numbers are in there too if you look closely.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -