I had a problem where a column in my table has data that is encoded using the System.Xml.XmlConvert.Encode method.
Now I need to manipulate this data in SQL and not find a way to duplicate the System.Xml.XmlConvert.Decode method.
So, I studied how I can use the System.XML namespace in SQL to access this method WITHOUT having to wrap it inside one of my own assemblies. Is it possible? For example, how can I access this assembly directly through T-SQL?
There are quite a few examples of writing add-ins using .NET for SQL. I believe you will need SQL 2005 or later to create the add-in.
Here is an example that is especially useful.
Creating CLR SQL A user-defined function to validate values ββusing @MSDN regular expressions
In your case, you probably want to write a function that takes a byte [] and returns a string (decoding), as well as 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 the corresponding wrapper function in SQL, which can take a hexadecimal string and turn it into varbinary (), if necessary.
change
Here are some more solid links to other links that are included in the previous link, in case it ever disappears.
How to create and run custom SQL CLR function defined by user @MSDN
Custom Attributes for @TechNet CLR Procedures