I have this simple C# code which is used by Sql Server to return TVF:
[SqlFunction(FillRowMethodName = "FillRow3")]
public static IEnumerable GetCsv(string csv)
{
string[] arr = csv.Split(',');
return arr;
}
public static void FillRow3(Object obj, out int val, out int index)
{
val = int.Parse((string)obj) ;
index = ??? <----------?
}
Hoever – I want to return a table which has 2 columns : ( val,index)
How can I return for each row , its index ( 0-based) according to arr
(obj is the row from arr.)
p.s –
I can create an array of MyItem which will contain [value,index] in the GetCsv method.
And then – obj row ( val+index) will be visible to FillRow3 method.
But I don’t want to do that.
It should look like this:
Notice, that no static variables are needed. If you don’t think static state inside of SQL Server is a problem please research this issue.