SqlChars
inherits .ToString()
from Object
which simply returns the type name. Use text.ToSqlString().ToString()
instead.
SQL CLR UDF Returning Type Name ()
-
31-05-2022 - |
Question
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
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow