22,210
社区成员
发帖
与我相关
我的任务
分享
create table tb(col varchar(20))
insert into tb values('01')
insert into tb values('002')
insert into tb values('0003333A')
go
update tb
set col = replace(col,'0','')
select * from tb
drop table tb
col
--------------------
1
2
3333A
(3 行受影响)
create table tb(col varchar(20))
insert into tb values('01')
insert into tb values('002')
insert into tb values('0003333A')
go
select substring(col , PATINDEX('%[^0]%',col) , len(col)) from tb
drop table tb
/*
--------------------
1
2
3333A
(所影响的行数为 3 行)
*/
update tb
set col = stuff(col,1,patindex('%[^0]%',col)-1,'')
where left(col,1) = 0
create table ljf
(c varchar(15))
insert into ljf
select '01' union all
select '002' union all
select '0003333A'
update ljf
set c=substring(c,
patindex('%[^0]%',c),
len(c)-patindex('%[^0]%',c)+1)
select * from ljf
c
---------------
1
2
3333A
(3 row(s) affected)