update table1 set aa= case when left(aa,1)='Q' then 'L'+right(aa,len(aa)-1) else aa end --或者 update table1 set aa= 'L'+right(aa,len(aa)-1) where left(aa,1)='Q'
update table1 set aa=stuff(aa,1,1,'L') where left(aa,1)='Q'
update table1 set aa = (case when left(aa,1) = 'Q' then 'L' + substring(aa,2,len(aa)-1) else aa end)
update table1 set aa=stuff(aa,charindex('Q',aa),1,'L') where aa like '%Q%'Q不是固定第1个字符时用stuff
update table1 set aa=stuff(aa,1,1,'L') where left(aa,1)='Q'
if object_id('[table1]') is not null drop table [table1]create table [table1] (aa varchar(6)) insert into [table1] select 'Q1234Q' union all select 'Q4321'update table1 set aa=stuff(aa,1,1,'L') where left(aa,1)='Q' select * from [table1] /* aa ------ L1234Q L4321 */
create table tbl( id varchar(20) not null, name varchar(20) not null )insert into tbl values('Q0411tracy','tracy') insert into tbl values('M0917kobe','kobe') insert into tbl values('Q0574tom','tom') insert into tbl values('N0755lucy','lucy') select *from tblupdate tbl set id='L'+right(id,len(id)-1) where left(id,1)='Q'
update table1 set aa= case when left(aa,1)='Q' then 'L'+right(aa,len(aa)-1) else aa end
--或者
update table1 set aa= 'L'+right(aa,len(aa)-1)
where left(aa,1)='Q'
set aa = (case when left(aa,1) = 'Q' then 'L' + substring(aa,2,len(aa)-1) else aa end)
update table1
set aa=stuff(aa,charindex('Q',aa),1,'L')
where aa like '%Q%'Q不是固定第1个字符时用stuff
if object_id('[table1]') is not null
drop table [table1]create table [table1] (aa varchar(6))
insert into [table1]
select 'Q1234Q' union all
select 'Q4321'update table1 set aa=stuff(aa,1,1,'L') where left(aa,1)='Q'
select * from [table1]
/*
aa
------
L1234Q
L4321
*/
id varchar(20) not null,
name varchar(20) not null
)insert into tbl values('Q0411tracy','tracy')
insert into tbl values('M0917kobe','kobe')
insert into tbl values('Q0574tom','tom')
insert into tbl values('N0755lucy','lucy')
select *from tblupdate tbl set id='L'+right(id,len(id)-1) where left(id,1)='Q'