Is these .net methods supported to call from SQL Stored Procedures?
public static int MultiplyMany(params int[] intArray)
{
int result = 1;
foreach(int now in intArray)
{
result *= now;
}
return result;
}
public static void TestOut(string name, out string firstName, out string lastName)
{
int spaceIndex = name.IndexOf(' ');
firstName = name.Substring(0, spaceIndex);
lastName = name.Substring(++spaceIndex);
}
What do you mean by "call from SQL SP"? You cannot call CLR methods directly from Transact-SQL. You can invoke them from T-SQL only by calling SQLCLR stored procedure/function/UDT method etc.
How do you expect to obtain an int[] array in SQL?
MultiplyMany method: you cannot make it as SQLCLR stored procedure, because there is no SQL type corresponding to int[]. If you will call it from another SQLCLR method - then, of course, you will be able to call it as you are already inside CLR.
If you are trying to multiply values from the column of the table it might be useful for you to look through the new SQL CLR User-Defined Aggregate.
TestOut method - you will have to create an SQLCLR stored procedure that will invoke this method to be able to call it from T-SQL. You can either add [SqlProcedure] attribute to the method so that SQLCLR SP will be created automatically by Visual Studio, or manually run the statement (don't forget to replace AssemblyName, YourNamespace and ClassName with correct ones ):
CREATE PROCEDURE dbo.TestOut
@.name nvarchar(250),
@.firstName nvarchar(125) output,
@.lastName nvarchar(125) output
AS
EXTERNAL NAME [AssemblyName].[YourNamespace.ClassName].[TestOut]
I agree with you for TestOut.
For the 1st method I didn't think that I would send array object offcourse, but you didnot notice the params keyword.
My question for this method is: is it supported to send undetermined number of parameters that will be put into array in the .net?
Thank you for your help.
|||No, it is not possible.Don't forget that each SQLCLR stored procedure has two parts: implementation on the CLR side and registration of the stored procedure on the SQL side. If the syntax of CREATE PROCEDURE statement doesn't allow undetermined number of parameters, you cannot expect it from SQLCLR stored procedure.|||
Thank you.
I am convinced.
No comments:
Post a Comment