就是自加1的问题,转换成numeric後,总就少个0。
----------------------------------------------
declare @a char(15),@b char(15)
select @a = '012345678912345 '
select @b = '012345678912349 '
WHILE CAST(@a AS NUMERIC) <= CAST(@b AS NUMERIC)
BEGIN
print (right( '000000000000000 '+ @a,15))
SELECT @a = CAST(@a AS NUMERIC) + 1
END
--结果
012345678912345
12345678912346
12345678912347
12345678912348
12345678912349
就第一条数据开头带0,剩下的都没有,怎么回事?求高手指点!
------解决方案--------------------
declare @a varchar(15),@b varchar(15) --定义为varchar
select @a = '012345678912345 '
select @b = '012345678912349 '
WHILE CAST(@a AS NUMERIC) <= CAST(@b AS NUMERIC)
BEGIN
print (right( '000000000000000 '+ @a,15))
SELECT @a = CAST(@a AS NUMERIC) + 1
END
------解决方案--------------------
declare @a char(15),@b char(15)
select @a = '012345678912345 '
select @b = '012345678912349 '
WHILE @a <[email protected]
BEGIN
print @a
SELECT @a = right( '0000000000000000 '+ ltrim(cast(@a as numeric)+1),15)
END