我想生成包含默认字符和4位数字的唯一字符串。
例如-
"AKL0001"
"AKL0002"
"AKL0010"
像这样
答案 0 :(得分:0)
尝试这样
WITH cte AS
( SELECT 1 AS Num
UNION ALL
SELECT Num + 1
FROM cte
WHERE Num < 10000
)
SELECT 'AKL'+RIGHT(CONCAT('0000',Num),4)
FROM cte
答案 1 :(得分:0)
尝试一下。您可以根据需要更改选项:
DECLARE @min bigint, @max bigint, @string VARCHAR(12)
SELECT @Min=1 ,@Max=1000, @string = 'AKL'
SELECT TOP (@Max-@Min+1) @string + RIGHT(@Min-1+row_number() over(order by t1.number) + 1000 * @max, 4) as N
FROM master..spt_values t1
CROSS JOIN master..spt_values t2