views:

53

answers:

3

SQL Server 2008 R2 has a new Master Data Services feature that includes some really nice regular expression matching & extraction functions:

http://msdn.microsoft.com/en-us/library/ee633712.aspx

I am running 2008 R2, and want to run those functions outside of the MDS database.

How can I? Is there a way to extract them and reapply them to my own db?

A: 

You can access the .NET Regex classes via CLR integration in SQL 2005/2008. See: Regular Expressions Make Pattern Matching And Data Extraction Easier

Joe Stefanelli
That is a functioning regex implementation, yes, but I wanted the MDS "written by the SQL team and shipped with SQL server" version. Still CLR, and I get a bonus warm and fuzzy from going the MDS route.
Travis Pettijohn
A: 

I figured it out and fully documented it (with screenshots) on my blog. http://www.pettijohn.com/2010/08/regular-expressions-in-sql-2008-r2.html

In summary:

  • Install MDS from D:\MasterDataServices\x64\1033_ENU
  • Run the Configuration Manager and set up a new MDS database. You will be copying from here and into your own database.
  • Script the Microsoft.MasterDataServices.DataQuality assembly (Programmability / Assemblies / Right click / Script as / Create)
  • Change the AUTHORIZATION to db_datareader
  • Find the functions you need (regex are under scalar), and right click, script, create.
  • Delete the USE block, and change the namespace to dbo, or one of your own.
  • Run all of the scripts on your own database, starting with the assembly.
Travis Pettijohn
Clever that you figured out how to do it but I wouldn't recommend this approach and certainly wouldn't allow it in my shop. Are you going to remember to keep your extracted copy in sync with any changes that occur in the MDS version via hot fixes, service packs, etc? In my opinion, the risks outweigh the rewards in this situation.
Joe Stefanelli
Surely it's no worse than using code from an article published three+ years ago.
Travis Pettijohn
But that code would be 100% within your control. You can't predict when Microsoft might decide to change the code deployed as part of MDS. For example, if they were to identify and fix a bug, your extracted code would still contain that bug unless you're hyper-vigilant about keeping it in sync.
Joe Stefanelli
+1  A: 

Go grab it while it's hot.

Adapted string functions and assembly from Sql Server 2008 R2 MDS

The package includes the following functions:

TVFs:

  • NGrams
  • RegexMatches
  • RegexSplit
  • Split

SVFs:

  • RegexExtract
  • RegexIsMatch
  • RegexIsValid
  • RegexMask
  • RegexReplace
  • Similarity
  • SimilarityDate
  • XmlTransform

I altered the default schema to dbo.

Denis Valeev