Developing By Me

Project Development and Design


    Variables allow SQL to have dynamic search criteria. The variables can be set internally to the SQL statements but they could also be set externally through another application. It is also possible to use a subquery to set the variable search however this will be covered in Subqueries. The different ways to define a variable are important however the syntax for the variable reference is the same. A variable always starts with the @ symbol such as ‘@var’. In the SQL code a variable is defined by two statements the first is ‘DECLARE @var AS DATETIME’ then it must be initialized with “SET @var = ‘1/1/2012’ ”. A variable can be defined with any variable type but the variable must match the same type as the column that it will be compared with. The most common variables are numbers and dates which are INT, BIGINT and DATETIME.

%d bloggers like this: