views:

196

answers:

2

Hi,
I am having an issue whereby a column within a table of 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?

A: 

This is a rather broad answer, but it should have everything you need.

MSDN

yodaj007
+1  A: 

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

meklarian
This uses a wrapper. I don't want to use a wrapper class. I'm trying to avoid having to use the Create Assembly sql code
Nikron
Ok, I see now. Creating a SQL Project and adding in code there. Brilliant, thanks a mil meklarian
Nikron