T-SQL Tutorial

SQL_VARIANT - TSQL Tutorial


On Transact SQL language the SQL_VARIANT is a data type that stores values of various SQL Server-supported data types.
SQL_VARIANT can be used in columns, parameters, variables, and the return values of user-defined functions. Column defined as sql_variant can store int, binary, and char values.

SQL_VARIANT syntax:

sql_variant

SQL_VARIANT example:

USE model;
GO
DECLARE @var1 sql_variant = 3
DECLARE @var2 sql_variant = 'Medicine'
SELECT * FROM courses WHERE id=@var1;
SELECT * FROM courses WHERE name=@var2;
GO