I have a SQL CLR function like this one:
public partial class UserDefinedFunctions {
[Microsoft.SqlServer.Server.SqlFunction(TableDefinition = "number int", FillRowMethodName = "FillRow")]
public static IEnumerable MyClrFunction(object obj) {
// read obj array input and then
var result = new ArrayList();
result.Add((SqlInt32)1);
result.Add((SqlInt32)2);
result.Add((SqlInt32)3);
return result;
}
public static void FillRow(object obj, out SqlInt32 number) {
number = (SqlInt32)obj;
}
}
I would like to use it this way:
DECLARE @x arrayOfInt
INSERT INTO @x VALUES (10)
INSERT INTO @x VALUES (20)
INSERT INTO @x VALUES (30)
SELECT * FROM dbo.MyClrFunction(@x)
arrayOfInt is:
CREATE TYPE [dbo].[arrayOfInt] AS TABLE(
[item] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[item] ASC
) WITH (IGNORE_DUP_KEY = OFF)
)
Problem I have is that arrayOfInt is incompatible with sql_variant. Is possible to write CLR Table-valued function which has an array (table) argument?