0

I am using a Visual Studio 2012 Database project with a CLR UDF (below). For some reason, after deploying it to the database, I call the function and I get the type name returned instead of the expected result.

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlChars FlattenText(SqlChars text)
    {
        return new SqlChars(Regex.Replace(text.ToString(), @"\s+", " ", RegexOptions.Multiline));
    }
}

When I call it like this:

SELECT TOP 1 dbo.FlattenText(MyColumn) AS MyResult FROM MyTable

Here is what I get returned:

System.Data.SqlTypes.SqlChars
4

1 回答 1

0

SqlChars inherits .ToString() from Object which simply returns the type name. Use text.ToSqlString().ToString() instead.

于 2013-06-08T19:45:54.830 回答