CREATE procedure pr_createjxc (@year varchar(4), @startdate int = 1, @start_date datetime)
WITH ENCRYPTION
as
begin
declare @fromD DateTime ,
@toD DateTime ,
@iFor integer ,
@iNum integer ,
@sDay varchar(6) ,
@sMonth varchar(6),
@isnow varchar(1),
@now varchar(6)
if (@startdate < 1) or (@startdate > 31)
begin
exec pr_error '日期错误,不能生成进销存期间'
return
end
select @now = substring(convert(varchar(10), @start_date, 112), 1, 6)
select @iFor = 1
Select @iNum = 12
select @sMonth = ''
select @sDay = convert(varchar, @startdate)
if @startdate < 10
select @sDay = '0' + @sDay
if exists(select 1 from sys_t_jxcdate where substring(jxc_month, 1, 4) = @year)
begin
exec pr_error '当前进销存区间已存在,不用再生成'
return
end
select @iFor = convert(int, substring(convert(varchar(10), @start_date, 112), 5, 2))
while @iFor <= @iNum
begin
select @sMonth = convert(varchar, @iFor)
if @iFor < 10
select @sMonth = '0' + @sMonth
select @sMonth = @year + @sMonth if @now = @sMonth
select @isNow = '1'
else
select @isNow = '0'
select @fromD = convert(DateTime, @sMonth + @sDay)
select @toD = DATEADD(month, 1, @fromD)
select @toD = DATEADD(Second , -1, @toD)
insert into sys_t_jxcdate(jxc_month, is_now, start_date, end_date)
select @sMonth, @isNow, @FromD, @ToD
select @iFor = @iFor + 1
end
end
CREATE procedure pr_createjxc
最新推荐文章于 2021-03-19 15:58:27 发布