So, starting with SQL Server 2008 Microsoft made improvements on declaring variables and assigning values to them. Here is an example for SQL Server 2008 and newer versions.
DECLARE @Startdate DATETIME = GETDATE()
DECLARE @AccountID INT = 12345
SELECT @Startdate AS StartDate,
@AccountID AS AccountID
However if you run the above statement in SQL 2005 or earlier you will get an error message. The only way above statement will work on SQL 2005 and earlier versions is;
DECLARE @Startdate DATETIME
DECLARE @AccountID INT
SELECT @Startdate = GETDATE(),
@AccountID = 12345
SELECT @Startdate AS StartDate,
@AccountID AS AccountID
As you see it is less of t-sql code for SQL Server 2008 and newer versions. There is some more enhancements but I will cover that in my next blog.
HTH,
Bulent
No comments:
Post a Comment