1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| CREATE PROC dpPMT_SGetMaintainSeq @MaintainCate VARCHAR(2)
AS --***********************累加编号************************************************* DECLARE @MaintainNo VARCHAR(12) IF NOT EXISTS(SELECT * FROM NumSeq WHERE Cate=@MaintainCate AND DATEDIFF(DAY,CrTime,GETDATE())=0) BEGIN INSERT INTO NumSeq(Cate,DateNo,Seq) values(@MaintainCate,RIGHT(CONVERT(VARCHAR(4),YEAR(GETDATE())),2)+ REPLICATE('0',2-LEN(MONTH(GETDATE())))+CONVERT(VARCHAR(2),MONTH(GETDATE())),0)
END ELSE BEGIN UPDATE NumSeq SET Seq=Seq+1 WHERE Cate=@MaintainCate AND DateNo=RIGHT(CONVERT(VARCHAR(4),YEAR(GETDATE())),2)+ REPLICATE('0',2-LEN(MONTH(GETDATE())))+CONVERT(VARCHAR(2),MONTH(GETDATE())) END
--************************组合编号*************************************************************** SELECT @MaintainNo=Cate+DateNo+REPLICATE('0',6-LEN(Seq))+CONVERT(VARCHAR(6),Seq) FROM NumSeq WHERE Cate=@MaintainCate AND DateNo=RIGHT(CONVERT(VARCHAR(4),YEAR(GETDATE())),2)+ REPLICATE('0',2-LEN(MONTH(GETDATE())))+CONVERT(VARCHAR(2),MONTH(GETDATE()))
SELECT @MaintainNo
|