Creating a CLR UDF with variable number of parameters

Posted by josephj1989 on Stack Overflow See other posts from Stack Overflow or by josephj1989
Published on 2010-05-24T05:27:07Z Indexed on 2010/05/24 5:31 UTC
Read the original article Hit count: 382

Filed under:
|
|
|

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 ?

© Stack Overflow or respective owner

Related posts about sql

Related posts about server