34,588
社区成员
发帖
与我相关
我的任务
分享
if object_id('tempdb..#')is not null drop table #
go
create table #(id varchar(10), t2 varchar(20))
insert # select 'aaa' , 'myid:111'
insert # select 'bbb' , 'yourid:222'
insert # select 'ccc' , 'herid:3333'
update # set t2=left(t2,charindex(':',t2))+id
select * from #
/*id t2
---------- --------------------
aaa myid:aaa
bbb yourid:bbb
ccc herid:ccc*/
declare @a table
(
id varchar(50),
t2 varchar(50)
)
insert into @a
select 'aaa' , 'myid:111' union
select 'bbb' , 'yourid:222'union
select 'ccc' , 'herid:3333'
update @a
set t2 = substring(t2,1,charindex(':',t2)) + id
select * from @a
结果:
aaa myid:aaa
bbb yourid:bbb
ccc herid:ccc
create table A(id varchar(10) , t2 varchar(20))
insert into a values('aaa' , 'myid:111')
insert into a values('bbb' , 'yourid:222')
insert into a values('ccc' , 'herid:3333')
go
update a
set t2 = left(t2 , charindex(':' , t2)) + id
select * from a
drop table a
/*
id t2
---------- --------------------
aaa myid:aaa
bbb yourid:bbb
ccc herid:ccc
(所影响的行数为 3 行)
/*
update a
set t2 = left(t2 , charindex(':')) + id
if object_id('tempdb..#')is not null drop table #
go
create table #(id varchar(10), t2 varchar(20))
insert # select 'aaa' , 'myid:111'
insert # select 'bbb' , 'yourid:222'
insert # select 'ccc' , 'herid:3333'
update # set t2=replace(replace(replace(t2,'111','aaa'),222,'bbb'),3333,'ccc')
select * from #
/*id t2
---------- --------------------
aaa myid:aaa
bbb yourid:bbb
ccc herid:ccc*/
update a
set t2 = substring(t2,1,charindex(':',t2)) + id