两个Table想用Union All进行合并
但其Table1中含有一列ColumnNameA都是Null空值
另一个Table2中ColumnNameA是有值的
此时如何进行合并?

解决方案 »

  1.   

    select ColumnNameA from Table1
    union all
    select ColumnNameA from Table2还是
    insert into Table1 select ColumnNameA from table2
      

  2.   

    楼上的已经很清楚了。如果再想完整点,加上case 判断一下后再Union 
      

  3.   

    第一个select 各列都用convert()来指定类型
      

  4.   


    --> 测试数据: @tablea
    declare @tablea table (id int,col varchar(4))
    insert into @tablea
    select 1,'a' union all
    select 2,'b' union all
    select 3,'c'select * from @tablea
    --> 测试数据: @tableb
    declare @tableb table (id int,col varchar(4))
    insert into @tableb
    select 4,null union all
    select 5,null union all
    select 6,nullselect * from @tableb
    select * from @tablea
    union all
    select * from @tableb/*直接合并就行,没有影响呀?
    id          col
    ----------- ----
    1           a
    2           b
    3           c
    4           NULL
    5           NULL
    6           NULL
    */
      

  5.   

    UNION ALL与你的空值有影响?
    看样子不是这样合并?