Creating a CLR UDF with variable number of parameters
- by josephj1989
Hi
I wanted a function to find the greatest of a list of String values passed in.
I want to invoke it as Select greatest('Abcd','Efgh','Zxy','EAD') from sql server.
It should return Zxy.
The number of parameters is variable.Incidentally it is very similar to
oracle GREATEST function.
So I wrote a very simple CLR function (Vs2008) and tried to deploy it.
See below
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString Greatest(params SqlString[] p)
{
SqlString max=p[0];
foreach (string s in p)
max = s.CompareTo(max) > 0 ? s : max;
return max;
}
};
But when I try to compile or deploy it I get the following error
Cannot find data type SqlString[].
Is it possible to satisfy my requirement using SQL CLR ?