September 2010
Intermediate to advanced
1704 pages
111h 8m
English
DECLARE StatementIn SQL Server 2008, you can now set a variable’s initial value at the same time you declare it. For example, the following line of code declares a variable named @ctr of type int and set its value to 100:
DECLARE @ctr int = 100
Previously, this functionality was only possible with stored procedure parameters. Assigning an initial value to a variable required a separate SET or SELECT statement. This new syntax simply streamlines the process of assigning an initial value to a variable. The value specified can be a constant or a constant expression, as in the following:
DECLARE @start_time datetime = getdate()
You can even assign the initial value via a subquery, as long as the subquery returns only a single ...
Read now
Unlock full access