自动生成流水号问题
我现在想生成一个流水号为7位的编码,开始是0000000,我如何实现自动增加!!!
[解决办法]
WITH Digits AS (
SELECT 0 as Number
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9
)
SELECT
(d5.Number * 100000)
+ (d4.Number * 10000)
+ (d3.Number * 1000)
+ (d2.Number * 100)
+ (d1.Number * 10)
+ d0.Number as Number INTO #t
FROM
Digits AS d0
, Digits AS d1
, Digits AS d2
, Digits AS d3
, Digits AS d4
, Digits AS d5
ORDER BY Number
SELECT RIGHT('000000'+CONVERT(VARCHAR(7),number),7) FROM #t