--select '1' id,'PP,*'NAME INTO #A
-- union all
--select '1','*' union all
--select '1','PP' union all
--select '2','uu,*' union all
--select '2','uu' union all
--select '2','*' union all
--select '3','' union all
--select '3','*' --select '1' id,'PP,*' NAME INTO #B
--union all
--select '2','UU,*'
--union all
--select '3','*'SELECT * FROM #a
SELECT * FROM #bUPDATE #a
SET #a.name=#b.name
FROM #b
WHERE #a.id=#b.id/*
id NAME
---- ----
1 PP,*
1 PP,*
1 PP,*
2 UU,*
2 UU,*
2 UU,*
3 *
3 *
*/
-- union all
--select '1','*' union all
--select '1','PP' union all
--select '2','uu,*' union all
--select '2','uu' union all
--select '2','*' union all
--select '3','' union all
--select '3','*' --select '1' id,'PP,*' NAME INTO #B
--union all
--select '2','UU,*'
--union all
--select '3','*'SELECT * FROM #a
SELECT * FROM #bUPDATE #a
SET #a.name=#b.name
FROM #b
WHERE #a.id=#b.id/*
id NAME
---- ----
1 PP,*
1 PP,*
1 PP,*
2 UU,*
2 UU,*
2 UU,*
3 *
3 *
*/
select '1' id,'PP,*' descr INTO #a union all
select '1','*' union all
select '1','PP' union all
select '2','uu,*' union all
select '2','uu' union all
select '2','*' union all
select '3','' union all
select '3','*' select '1' id,'PP,*' descr INTO #b union all
select '2','UU,*' union all
select '3','*'UPDATE a SET descr=b.descr
from #a a
JOIN #b b ON a.id=b.idSELECT * FROM #a
create table a(id varchar(10),descr varchar(20))insert into a
select '1' id,'PP,*' union all
select '1','*' union all
select '1','PP' union all
select '2','uu,*' union all
select '2','uu' union all
select '2','*' union all
select '3','' union all
select '3','*' create table b(id varchar(10),descr varchar(20))insert into b
select '1' id,'PP,*' descr union all
select '2','UU,*' union all
select '3','*'
go--更新数据
UPDATE a
SET descr=b.descr
from b
where a.id=b.id
SELECT * FROM a
/*
id descr
1 PP,*
1 PP,*
1 PP,*
2 UU,*
2 UU,*
2 UU,*
3 *
3 *
*/
update A SET A.Name=B.Name from A,B Where A.Id=B.Id