sqlserver 创建存储过程计算两年 24 个月的时间(只求年月)

直接上代码:

---建立查询数据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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值