次のような SQL CLR 関数があります。
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;
}
}
このように使用したいと思います:
DECLARE @x arrayOfInt
INSERT INTO @x VALUES (10)
INSERT INTO @x VALUES (20)
INSERT INTO @x VALUES (30)
SELECT * FROM dbo.MyClrFunction(@x)
arrayOfIntは次のとおりです。
CREATE TYPE [dbo].[arrayOfInt] AS TABLE(
[item] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[item] ASC
) WITH (IGNORE_DUP_KEY = OFF)
)
問題は、arrayOfIntが sql_variant と互換性がないことです。配列 (テーブル) 引数を持つ CLR テーブル値関数を記述できますか?