Search code examples
sqlsql-serverclrsqlclr

How to create and execute CLR UDF


I really tried several blogs and videos, but I am trying to execute a simple "CLR UDF" shown here. I have SSMS/SQL Server, I've already enabled CLR, I just don't know where to go from here. Is this an assembly? I cannot find out what steps to take. Here are the things that I tried this. But it's not working. I found a solution that uses Visual Studio, but is there a way to create a CLR in just SSMS? This code won't compile.

Sorry I really don't know if that code is assembly or not. Thank you very much for your help


Solution

  • SQLCLR is the ability to run .NET code internally within SQL Server. This is not the full .NET as there are quite a few restrictions, and not all of the .NET Framework libraries are available to use. This is an area where one needs to be rather careful due to not wanting to negatively impact SQL Server.

    No, the code in the answer to that linked question is not an assembly. It is source code that gets compiled into an assembly, which is a binary file.

    No, SSMS alone will not help you. It does not compile .NET code into an assembly. For that you need Visual Studio, or at least just the C# compiler itself. In fact, SSMS is not required for any part of writing, compiling, or deploying/publishing SQLCLR projects.

    Those tutorials don't really provide much information. I have written more extensively at the following locations:

    Side note: since you appear to be wanting the Levenshtein Distance function, that is available in a ready to install library that I wrote called SQL# (SQLsharp). However, the String_LevenshteinDistance functions (including the better String_DamerauLevenshteinDistance functions) are only available in the paid-for version, not in the Free version.