直接上代码:
---建立查询数据24个月参数列临时表
create table #PMCPara
(
FID int identity(1,1),
FPara int default(0),
)
--根据传入年月数字计算24个月
Declare @FYearMonth as int
Set @FYearMonth=@FYearMonthP
--print @FYearMonth/100
--print @FYearMonth%100
Declare @FYear as int
Declare @FMonth as int
Declare @FValue as int
--定议24个月
Declare @n as int
Set @n=24
Declare @i as int
Set @i=1
--循环计算24个月具体时间插入临时表
--插拉当前值
Insert into #PMCPara(FPara) values (@FYearMonth)
--循环递减值
While (@i<@n)
Begin
if (@FYearMonth%100<>1)
begin
Set @FValue=@FYearMonth-1
end
else
begin
Set @FValue =(@FYearMonth/100-1)*100+12
end
Insert into #PMCPara(FPara) values (@FValue)
set @FYearMonth=@FValue
Set @i=@i+1
End