O'Reilly logo
  • Dustin Waybright thinks this is interesting:

DECLARE @orderyear int = 2007;
SELECT orderyear, qty
FROM Sales.OrderTotalsByYear
WHERE orderyear = @orderyear;


Cover of Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012


Using DECLARE @ is an option at the beginning of queries where multiple table expressions result in different date sets, YoY comparisons for example. It makes the date manipulation easier as you don't have to scan the query code for the dates to update when changing periods.