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
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