下表是我把两个表full join出来的结果,怎么让它变成表2中的结果?
表1:
  A       B        C        D
0001 45 0001 37
0026 49 0026 326
0031 12 NULL NULL
0032 57 0032 63
0037 12 0037 3
NULL NULL 0042 35
NULL NULL 0043 11表2:0001 45 37
0026 49 326
0031 12 NULL
0032 57 63
0037 12 3
0042 NULL 35
0043 NULL 11

解决方案 »

  1.   

    select coalesce(a,c) A,
           B,
           D
    from [表1] a full join [表2] b
    on a.id=b.id
      

  2.   

    select (case  when A is null then C else A end),B,D from Ta
      

  3.   

    create table gjlsss 
    (
    A varchar(10),
    B varchar(10),
    C varchar(10),
    D varchar(10)
    )insert into gjlsss
    select '0001', '45' ,'0001', '37' union all  select 
    '0026' ,'49' ,'0026', '326' union all  select 
    '0031' ,'12' ,'NULL', 'NULL' union all  select 
    '0032' ,'57' ,'0032', '63' union all  select 
    '0037', '12' ,'0037','3' union all  select 
    'NULL' ,'NULL' ,'0042' ,'35' union all  select 
    'NULL', 'NULL', '0043' ,'11'select  (case A  when 'null'   then C else A end)as AC ,B,D from gjlsss===============================0001 45 37
    0026 49 326
    0031 12 NULL
    0032 57 63
    0037 12 3
    0042 NULL 35
    0043 NULL 11
      

  4.   

    --假設列名都為ID, Value
    Select
    IsNull(A.ID, B.ID) As ID,
    A.Value,
    B.Value
    From
    表1 A 
    Full Join
    表2 B
    On A.ID = B.ID
      

  5.   

    樓主用的CASE?你只需要在原來的FULL JOIN語句的基礎上修改少許,就可以得到你的結果的.