Msg 8116 - Argument data type sql_variant is invalid for argument 1 of function

15 April,2016 by Jack Vamvas

A colleague presented me with the Msg 8116 - Argument data type sql_variant is invalid for argument 1 of function error message when creating a new sql script.

The Msg 8116 error message was generated by executing this code:

 select reverse(serverproperty('machinename'))

 

The REVERSE string function supports return types of VARCHAR or NVARCHAR. SQL Server doesn't  not support implicit conversions from sql_variant data to VARCHAR or NVARCHAR.  When an attempt is made to implicitly convert from sql_variant data type into VARCHAR or NVARCHAR , the Msg 8116 - Argument data type sql_variant is invalid for argument 1 of function  message is returned

A simple fix for the code my colleageue presented is to  explicitly CONVERT or CONVERT the sql_variant to a VARCHAR

 

Read More on Data types

Implicit conversion of data types in the query engine (SQL Server DBA)

Find column data types using sys.types and sys.syscolumns (SQL ...

SQL Server – large value types out of row and performance (SQL ...

 

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Msg 8116 - Argument data type sql_variant is invalid for argument 1 of function


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer