Every variable name begins with an at.
declare @i int set @i = 5 declare @j int set @j = 6 print @i+@j -- displays 11
declare @k char set @k = '5' declare @l char set @l = '6' print @k+@l -- displays 56
The possible variable types are similar to the table fields ones:
Those beginning by "n" are in Unicode format.
char, nchar, nvarchar, ntext, text, varchar.
To save a few memory space, it's possible to set a characters number limit during the declaration:
The variable of characters maximum size is 2 GB :
decimal, int (tinyint, smallint, bigint), float, money, numeric, real, smallmoney.
date, datetime, datetime2, datetimeoffset, smalldatetime, time.
In addition to the native types, it's possible to create one's own data types with
SQL_VARIANT_PROPERTY returns a given field type. Example:
SELECT SQL_VARIANT_PROPERTY(Field1, 'BaseType') FROM table1
Manage research, learning and skills at IT1me. Create an account using LinkedIn to manage and organize your IT knowledge. IT1me works like a shopping cart for information -- helping you to save, discuss and share.