会员开通时间处理的存储过程|软件开发

create proc ProcSetOpenMonth(@GcompanyUser varchar(120),@months int)
as
begin
declare @PoorNum int
if exists(select * from Hr_OpenMonth where GcompanyUser=@GcompanyUser)
begin
--if(datediff(d,GstartDate,getdate()))
select @PoorNum=datediff(d,getdate(),dateadd(m,GopenMonth,GstartDate)) from Hr_OpenMonth
if(@PoorNum>=0)
begin
update Hr_OpenMonth set GstartDate=getdate(),GopenMonth=@months+datediff(m,getdate(),dateadd(m,GopenMonth,GstartDate)) where GcompanyUser=@GcompanyUser
end
else
begin
update Hr_OpenMonth set GstartDate=getdate(),GopenMonth=@months where GcompanyUser=@GcompanyUser
end
end
else
begin
insert into Hr_OpenMonth(GcompanyUser,GstartDate,GopenMonth) values(@GcompanyUser,getdate(),@months)
end
end
go
原文地址:https://www.cnblogs.com/bestsaler/p/1835875.html