CREATE PROCEDURE dbo.FORM_ECS_NO
@form_kind nvarchar (50),
@form_no nvarchar (50)
AS declare @dept nvarchar (50)
declare @date nvarchar (50)
declare @year nvarchar (50)
declare @month nvarchar (50)
declare @dateleft nvarchar (50)
declare @dateright nvarchar (50)
declare @ECS_NO nvarchar (50)
declare @ECS nvarchar (50)
declare @ECS_NEWNO NVARCHAR (50) select @dept=left(a.dept_code,4) FROM am_employee a,FORM b where a.login_name=b.ps_ja and b.form_no=@form_no
set @year=right(datepart(year,getdate()),2)
set @month=datepart(month,getdate())
if len(@month)=1
set @month='0'+@month
set @date=@year+@month
set @dateleft=@dept+'-'+@date+'-'
--PRINT @dateleft
if exists(select * from FORM where left(ltrim(DOC_NO),10)=@dateleft)
BEGIN
select @ECS_NO=DOC_NO from FORM where left(ltrim(DOC_NO),10)=@dateleft
set @ECS=right(rtrim(@ECS_NO),3)+1
while (len(@ECS)<>3)
SET @ecs='0'+@ECS
END
else
BEGIN
set @ECS='001'
END
set @ECS_NEWNO=@DATEleft+@ECS
select @ECS_NEWNO
update FORM set DOC_NO=@ECS_NEWNO where form_no=@form_no
GO
@form_kind nvarchar (50),
@form_no nvarchar (50)
AS declare @dept nvarchar (50)
declare @date nvarchar (50)
declare @year nvarchar (50)
declare @month nvarchar (50)
declare @dateleft nvarchar (50)
declare @dateright nvarchar (50)
declare @ECS_NO nvarchar (50)
declare @ECS nvarchar (50)
declare @ECS_NEWNO NVARCHAR (50) select @dept=left(a.dept_code,4) FROM am_employee a,FORM b where a.login_name=b.ps_ja and b.form_no=@form_no
set @year=right(datepart(year,getdate()),2)
set @month=datepart(month,getdate())
if len(@month)=1
set @month='0'+@month
set @date=@year+@month
set @dateleft=@dept+'-'+@date+'-'
--PRINT @dateleft
if exists(select * from FORM where left(ltrim(DOC_NO),10)=@dateleft)
BEGIN
select @ECS_NO=DOC_NO from FORM where left(ltrim(DOC_NO),10)=@dateleft
set @ECS=right(rtrim(@ECS_NO),3)+1
while (len(@ECS)<>3)
SET @ecs='0'+@ECS
END
else
BEGIN
set @ECS='001'
END
set @ECS_NEWNO=@DATEleft+@ECS
select @ECS_NEWNO
update FORM set DOC_NO=@ECS_NEWNO where form_no=@form_no
GO
相关文章
暂无评论...