Mega Code Archive

 
Categories / MSSQL Tutorial / Data Types
 

Sql_variant data type is designed to allow a single variable, column, or parameter to store values in different data types

Internally, variant objects record two values: The actual value The metadata describing the variant: base data type, maximum size, scale, precision, and collation 13> Create table Lookup( 14>    LookupGroupId tinyint, 15>    LookupId smallint, 16>    LookupValue sql_variant) 17> Go 1> 2> 3> Insert Lookup (LookupGroupId, LookupId, LookupValue) 4>      Values (2, 34, 'VAR') 5> Insert Lookup (LookupGroupId, LookupId, LookupValue) 6>      Values (3, 22, 2000) 7> Insert Lookup (LookupGroupId, LookupId, LookupValue) 8>      Values (4, 16, '1/12/2000') 9> Insert Lookup (LookupGroupId, LookupId, LookupValue) 10>      Values (4, 11, $50000) 11> GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) 1> 2> drop table Lookup; 3> GO 1> 2> 3>