Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

In SQL Server 2008 it is possiblle to declare and initialize a variable in one statement.:

declare @cntr int = 0

select @cntr as cntr

cntr
-----------
0

(1 row(s) affected)

Furthermore , when adding or subtracting data from the current content of a variable, it is possible to use the C# style syntax of += and -=. So the following code snippet will work in SQL Server 2008, but not in earlier versions of SQL Server:

declare @cntr int = 0

select @cntr as cntr

while (@cntr < 10)
begin
	set @cntr += 1
end

select @cntr as cntr

while (@cntr > 0)
begin
	set @cntr -= 1
end

select @cntr as cntr

cntr
-----------
0

(1 row(s) affected)

cntr
-----------
10

(1 row(s) affected)

cntr
-----------
0

(1 row(s) affected)

The SQL Server 2005 equivalent of this code snippet is:

declare @cntr int 

set @cntr = 0

select @cntr as cntr

while (@cntr < 10)
begin
	set @cntr = @cntr + 1
end

select @cntr as cntr

while (@cntr > 0)
begin
	set @cntr = @cntr - 1
end

select @cntr as cntr

cntr
-----------
0

(1 row(s) affected)

cntr
-----------
10

(1 row(s) affected)

cntr
-----------
0

(1 row(s) affected)

 © Evident Interactive BV