Could this be better? .NET 2.0 compatibility for SQL Server 2005:
public static SqlString RegexSubstring(SqlString regexpattern,
SqlString sourcetext,
SqlInt32 start_position)
{
SqlString result = null;
if (!regexpattern.IsNull && !sourcetext.IsNull && !start_position.IsNull)
{
int start_location = (int)start_position >= 0 ? (int)start_position : 0;
Regex RegexInstance = new Regex(regexpattern.ToString());
result = new SqlString(RegexInstance.Match(sourcetext.ToString(),
start_location).Value);
}
return result;
}
This is my first attempt at writing CLR functions/etc for SQL Server - is it absolutely necessary to use SqlString/etc data types for parameters?