标签:
找到记录中最大的编码,如“0005”,新增的一条记录,需要将编码设置为“0006”。
DECLARE @MaxCode CHAR(4) SELECT @MaxCode = MAX(a.Code) FROM dbo.jd_DeptPlanTaskCompile a LEFT JOIN dbo.jd_DeptPlanCompile b ON a.PlanID = b.ID WHERE a.Level = 1 AND a.PlanID = ‘299A02A8-8D4F-E411-80EF-00155D0A6F04‘ IF @MaxCode IS NULL OR @MaxCode = ‘‘ BEGIN SET @MaxCode = ‘0000‘ END SELECT REPLICATE(‘0‘,4 -LEN(CAST ((CAST (@MaxCode AS INTEGER) + 1) AS VARCHAR))) + CAST ((CAST (@MaxCode AS INTEGER) + 1) AS VARCHAR)
标签:
原文地址:http://www.cnblogs.com/lideqiang/p/4474350.html