update a set id=stuff(id,1,1,'0') update a set id='0'+right(id,len(id)-1) update a set id='0'+substring(id,2,8000)
update a set id=stuff(id,1,1,'0')
还有这种方法: declare @table table(id varchar(10)) insert into @table select '1245' union all select '45?1' union select '9?11' ---- select replace(id,left(id,1),'0') as id from @table /* id ----- 0245 05?1 0?11 */
小弟又有问题了~~ 问题: 在 a 表中 id 1245 45?1 9?11 如何能把记录中的第一位替换成0 替换后的结果如下: id 0245 05?1 0?11 希望各位高手慷慨解囊!!!! ------------------------------------------update a set id = '0' + substring(id , 2, len(id))
set id=stuff(id,1,1,'0')
update a
set id='0'+right(id,len(id)-1)
update a
set id='0'+substring(id,2,8000)
set id=stuff(id,1,1,'0')
还有这种方法:
declare @table table(id varchar(10))
insert into @table
select '1245'
union all
select '45?1'
union
select '9?11'
----
select replace(id,left(id,1),'0') as id from @table
/*
id
-----
0245
05?1
0?11
*/
问题:
在 a 表中
id
1245
45?1
9?11 如何能把记录中的第一位替换成0
替换后的结果如下:
id
0245
05?1
0?11
希望各位高手慷慨解囊!!!!
------------------------------------------update a set id = '0' + substring(id , 2, len(id))