Using a RegEx in a SQL Query

Posted by Jim B on Stack Overflow See other posts from Stack Overflow or by Jim B
Published on 2010-06-15T13:30:32Z Indexed on 2010/06/15 13:32 UTC
Read the original article Hit count: 273

Filed under:
|
|

Hey Everyone,

Here's the situation I'm in: We have a field in our database that contains a 3 digit number, surrounded by some text. This number is actually a PK in another table, and I need to extract this out so I can implement a proper FK relationship. Here's an example of what would currently reside in the column:

Some Text Goes Here - (305) Followed By Some More Text

So, what I'm looking to do is extract the '305' from the column, and hopefully end up with a result that looks something like this (pseudo code)

SELECT
   <My Extracted Value>,
   Original Column Text,
   Id
FROM dbo.MyTable

It seems to me that using a Regex match in my query is the most effective way to do this. Can anybody point me in the right direction?

© Stack Overflow or respective owner

Related posts about sql

Related posts about regex