Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Server CLR Functions

While writing a CLR function Sql Server can we use namespaces ?

namespace SomeName1.SomeName2
{
   public static class SomeClass
   {
       [SqlFunction]
       public static SqlString SomeMethod(SqlString input)
       {
          // ....
       }
   }
}

If so, then how do we call this function from SqlServer. In other words how do we call CLR functions from SQL Server with namespaces?

like image 486
Debjit Avatar asked Jul 27 '11 17:07

Debjit


1 Answers

Yes, you absolutely can:

CREATE FUNCTION SomeMethod(@input VarChar(200))
RETURNS VarChar(200) WITH EXECUTE AS CALLER AS

EXTERNAL NAME [SomeName1.SomeName2].[SomeName1.SomeName2.SomeClass.SomeMethod]

Where [SomeName1.SomeName2] in the first part is the assembly as named in SQL Server, and the rest ([SomeName1.SomeName2.SomeClass.SomeMethod]) is the fully qualified function name, including the namespace.

Incidentally, if you deploy from Visual Studio it handles a lot of this for you.

like image 105
Yuck Avatar answered Oct 24 '22 02:10

Yuck