[英]T-SQL concatenate an incremental row number
I want to increase the number by concatenating with some value. 我想通过连接一些值来增加数量。
for Ex: 例如:
declare @i int
select @i =1
select right('000' + convert(varchar(3),@i),3)
output is : 001
输出为:
001
if my @i value
increases to 1005 如果我的
@i value
增加到1005
then the output should be: 1005
那么输出应为:
1005
I know I can increase the number '0000' , but I want this start with 3 digits
then if @i value reach 1000
then I want in 4 digits
like this 1000,1001,1002...
我知道我可以增加数字'0000',但是我想
start with 3 digits
然后如果@i value reach 1000
那么I want in 4 digits
例如1000,1001,1002...
is there any way to get this.. Thanks in advance. 有什么办法可以做到这一点..预先感谢。
SELECT CASE WHEN @i < 1000 THEN RIGHT('000' + CONVERT(VARCHAR(3),@i),3)
ELSE CONVERT(VARCHAR(4),@i)
END /* CASE */
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.