create table #(bm varchar(20) not null)insert # select '12345|g' union all select '123456|ml' union all select '2345|支' union all select '5678910|tttt'----请问如何替换"|"之前的数据,非常感谢!
create table #a( bm varchar(20) not null, id varchar(10) not null )create table #b( id varchar(10) not null, mc varchar(20) not null ) insert #a select '12345|g','1' union all select '123456|ml','2' union all select '2345|支','3' union all select '5678910|tttt','4'insert #b select '1','99001A' union all select '2','990011AB' union all select '3','980867C' union all select '4','9XC56'#a.id=#b.id---更新#a表的bm字段,将#a.bm中'|'之前的全部用#b表中的mc代替,非常感谢!
SELECT 'a'+RIGHT(bm,LEN(bm)-CHARINDEX('|',bm)+1) FROM # 你可以把a 替换成一个列名。
select REPLACE ( #a.bm , substring(#a.bm,1,charindex('|',#a.bm) - 1) , #b.mc ) from #a ,#b where #a.id=#b.id
create table #a(
bm varchar(20) not null,
id varchar(10) not null
)create table #b(
id varchar(10) not null,
mc varchar(20) not null
)
insert #a
select '12345|g','1'
union all
select '123456|ml','2'
union all
select '2345|支','3'
union all
select '5678910|tttt','4'insert #b
select '1','99001A'
union all
select '2','990011AB'
union all
select '3','980867C'
union all
select '4','9XC56'#a.id=#b.id---更新#a表的bm字段,将#a.bm中'|'之前的全部用#b表中的mc代替,非常感谢!
你可以把a 替换成一个列名。