我正在尝试使用案例语句设置变量值以确定财政年度,具体取决于月份,但我得到了财政年度返回的 Null 值:
declare
@Costcentre varchar(50)
,@dt date
,@dty int
,@dtm int
select @Costcentre = 'CAM'
SELECT @dt = '2012-09-30'
select @dtm = DATEPART(month,@dt)
select
@dty = case when @dtm between 4 and 12 then DATEPART(year,@dt) + 1 end
,@dty = case when @dtm between 1 and 3 then DATEPART(year,@dt) end
select @dty