日期:2014-05-18  浏览次数:20642 次

一个表里累加数值(内详)在线等!
dh
0931105
0931106
0931107
... ...
... ...
... ...
... ...下面还有好多

问:我有一个表如上图,我现在想在dh 上每个加 1 ,变成如下图。我试过 dh+1 但前面的0没了,变成 931106,931107这种的了。

 dh
0931106
0931107
0931108
... ...
... ...
... ...
... ...下面还有好多

------解决方案--------------------
SQL code

select right('0000000' + rtrim(cast('0931105' as int)+1), 7);

select right('0000000' + rtrim(cast(dh as int)+1), 7);

------解决方案--------------------
SQL code

--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test]([dh] varchar(7))
insert [test]
select '0931105' union all
select '0931106' union all
select '0931107'


update test 
set [dh]='0'+ltrim(CAST([dh] as int)+1)
select * from test
/*
dh
0931106
0931107
0931108
*/