当前位置: 代码迷 >> Sql Server >> 一个表里累加数值(内详)
  详细解决方案

一个表里累加数值(内详)

热度:44   发布时间:2016-04-27 13:08:15.0
一个表里累加数值(内详)在线等!
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 allselect '0931106' union allselect '0931107'update test set [dh]='0'+ltrim(CAST([dh] as int)+1)select * from test/*dh093110609311070931108*/
  相关解决方案