看了好一会儿,有点明白楼主的意思了,看看是不是你的意思:if object_id('[a]') is not null drop table [a] go create table [a]([fdsono] int,[fdReplacePartList] varchar(20)) insert [a] select 1234,'a,b,f' go if object_id('[b]') is not null drop table [b] go create table [b]([fdsono] int,[fdStatus] int) insert [b] select 1234,1 union all select 1234,2 union all select 1234,3 goselect id=identity(int,1,1),* into # from bupdate a set a.[fdReplacePartList]=case when b.id=1 and [fdStatus]=1 then replace([fdReplacePartList],'a','9999') when b.id=2 and [fdStatus]=1 then replace([fdReplacePartList],'b','9999') when b.id=3 and [fdStatus]=1 then replace([fdReplacePartList],'c','9999') else [fdReplacePartList] end from a,# b where a.[fdsono]=b.[fdsono]select * from a /* fdsono fdReplacePartList ----------- -------------------- 1234 9999,b,f(1 行受影响) */ drop table #
go
create table [a]([fdsono] int,[fdReplacePartList] varchar(20))
insert [a] select 1234,'a,b,f'
go
if object_id('[b]') is not null drop table [b]
go
create table [b]([fdsono] int,[fdStatus] int)
insert [b] select 1234,1
union all select 1234,2
union all select 1234,3
goselect id=identity(int,1,1),* into # from bupdate a
set a.[fdReplacePartList]=case
when b.id=1 and [fdStatus]=1 then replace([fdReplacePartList],'a','9999')
when b.id=2 and [fdStatus]=1 then replace([fdReplacePartList],'b','9999')
when b.id=3 and [fdStatus]=1 then replace([fdReplacePartList],'c','9999')
else [fdReplacePartList]
end
from a,# b
where a.[fdsono]=b.[fdsono]select * from a
/*
fdsono fdReplacePartList
----------- --------------------
1234 9999,b,f(1 行受影响)
*/
drop table #