Operand Type Clash
The error is correct, you can't implicitly (or explicitly) cast a VARCHAR(MAX)
to sql_variant
. If Name
is a VARCHAR(MAX)
you will need to convert it to a compatible type (like VARCHAR(8000)
in order to pass it in as a parameter to sys.fn_sqlvarbasetostr()
see msdn:
sql_variant objects can hold data of any SQL Server data type except text, ntext, image, varchar(max), nvarchar(max), varbinary(max), xml, timestamp, and Microsoft .NET Framework common language runtime (CLR) user-defined types. An instance of sql_variant data also cannot have sql_variant as its underlying base data type.
If you need the functionality of sys.fn_sqlvarbasetostr()
and can't down convert your col without losing data, you may need to roll your own version of that function. CLR would be a good bet.