我想使用我声明局部变量,例如as 子句
我得到去年和今年
declare @lastYear varchar(4)=datepart(YEAR,DATEADD(year,-1,GETDATE()));
declare @currentYear varchar(4)=datepart(YEAR,DATEADD(year,0,GETDATE()));
和
我想像上面一样使用,
select a.totalCountLy as @lastYear, a.totalCountLy as @currentYear from TableName as a (nolock
结果就像
2011 2012
------------------
1000 5000
400 1000
有什么建议么。谢谢。