服务热线:

4006-6500-28

新闻资讯
联系我们

电话:400-665-0028


您当前位置:首页 > 新闻资讯  > 知识学习 > 正文知识学习
手工输入金蝶凭证号自动补号的SQL脚本
添加时间:2022-6-2

DECLARE @FNumber INT,@fstartnumber INT ;

SET @fstartnumber=900

SELECT ROW_NUMBER() OVER (ORDER BY FNumber)+@fstartnumber-1 AS FIndex, a.FNumber

INTO #tmp

FROM(SELECT FNumber

     FROM t_Voucher

     WHERE FYear=2020 AND FPeriod=7 AND FGroupID=1

     UNION

     SELECT FNumber

     FROM t_VoucherBlankOut

     WHERE FYear=2020 AND FPeriod=7 AND FGroupID=1) a WHERE a.FNumber>=@fstartnumber;


IF NOT EXISTS (SELECT * FROM #tmp AS t WHERE t.FIndex

SELECT @FNumber=ISNULL(MAX(FIndex), 0)+1 FROM #tmp;

ELSE

    SELECT @FNumber=ISNULL(MIN(t.FIndex), 0)

    FROM #tmp AS t

    WHERE t.FIndex

DROP TABLE #tmp;


SELECT @FNumber;