-- 建立测试表
create table #t(a varchar(20))
insert #t
select 'V000000000'
union select 'V000000001'
union select 'V000000006'
union select 'V000000008'
union select 'V000000009'
union select 'V000000012'
union select 'V000000050'
union select 'V000000056'
union select 'V000000086'
union select 'V000000112'-- 更新前
select * from #tdeclare @i int
set @i = -1
update #t set a = 'V000000' + right(('00' + cast(@i as varchar)),3),@i = @i +1-- 更新后
select * from #tdrop table #t
create table #t(a varchar(20))
insert #t
select 'V000000000'
union select 'V000000001'
union select 'V000000006'
union select 'V000000008'
union select 'V000000009'
union select 'V000000012'
union select 'V000000050'
union select 'V000000056'
union select 'V000000086'
union select 'V000000112'-- 更新前
select * from #tdeclare @i int
set @i = -1
update #t set a = 'V000000' + right(('00' + cast(@i as varchar)),3),@i = @i +1-- 更新后
select * from #tdrop table #t
解决方案 »
- SQL2005 无法登陆
- 从远程服务器大量数据中取出少量的优化问题
- 有谁能给我详细的解释一下索引的作用?
- 求一复杂sql语句,
- 如何迭代sql update语句更新的记录?
- 一个表的description 字段类型定义为 nvarchar 4000,但是我最多只能在里面放1023个汉字, 为什么?
- 没遇到过的统计,望各位大哥大姐帮帮忙
- sql server 2000 主从表不同步的奇怪问题 DELPHI+sql server 2000
- 怎么得到ms sql server的某个本地实例(或服务)的所有数据库列表?
- 求您的 MRP 运算 存储过程 或 代码实现过程
- 来来,大家帮个忙,怎样将字符串变成列类型!看不懂是吧,进来我详细说一下
- 求一简单的sql语句!在线等``` 50分! 解决就结贴!(补30分!)
set @i = -1
update t set 列 = 'V000000' + right(('00' + cast(@i as varchar)),3),@i = @i +1
select 'V'+right('00000000'+cast( ( select sum(1) as a
from table1
where id<=b.id
) as varchar(8)
),8
) as vcol,
col2,
...
from table1 b
order by id