select * from B 
union 
select * from A where not exists(select 1 from B where id=A.id)

解决方案 »

  1.   

    select A.id,isnull(B.name,A.name)name from A left join B on A.id=B.id
      

  2.   

    select  A.id , (CASE WHEN B.name  IS NOT NULL THEN B.name  ELSE A.name END ) AS NAME
    from A left outer join B 
    ON A.id=B.id
      

  3.   

    declare @A table(ID varchar(4),Name varchar(8))
    insert into @A select '001','张三'
    insert into @A select '002','李四'declare @B table(ID varchar(4),Name varchar(8))
    insert into @B select '001','新张三'select * from @B 
    union 
    select * from @A a where not exists(select 1 from @B where id=A.id)/*
    ID   Name     
    ---- -------- 
    001  新张三
    002  李四
    */
      

  4.   

    Select A表.id,isnull(B表.name,A表.name) From A表 
        Left join B表 A表.id = B表.id
      

  5.   

    select id,name from B 
    union 
    select id,name from A where not exists(select 1 from B where id=A.id)
      

  6.   

    多谢各位,已经测试通过!THANK!