I am having an issue whereby a column within a table o开发者_开发百科f mine has data which is encoded using the System.Xml.XmlConvert.Encode method.
Now I need to manipulate this data within SQL and have not found a way to duplicate the System.Xml.XmlConvert.Decode method.
So I've been investigating how I can use the System.XML namespace within SQL to access this method WITHOUT having to wrap it inside one of my own assemblies. Is this possible? i.e. how can I access this assembly directly via T-SQL?
There quite a few examples of writing add-ins using .NET for SQL. I believe you will need to have SQL 2005 or newer to create an add-in.
Here is an example that is particularly useful.
Creating CLR SQL User Defined Function to Validate Values Using Regular Expressions @ MSDN
In your case, you will probably want to write a function that takes a byte[] and returns a string (decode), along with a corresponding function that takes a string and returns a byte[].
Actually I'm not sure that you can directly use byte[], but you should be able to write a corresponding wrapper function in SQL that can take a hex string and turn it into a varbinary() if that is necessary.
edit:
Here are some more durable links to other references that are included in the prior link, just in case it ever disappears.
How to: Create and Run a CLR SQL User-Defined Function @ MSDN
Custom Attributes for CLR Routines @ TechNet
精彩评论