表1:  
      ID1           ID2      String1       String2
      String3       Null
      String4       String5
      Null          String6得出的结果
表2:  ID
      String1
      String2 
      String3
      String4
      String5
      String6
表1 中 第一行即"String1","String2"不会为空(Null),但是后面几行中的"String"是否为空(Null)是随机的.
通过怎么样处理后把"表1"中的所有记录(String)合并到一列中,并且过滤为"Null"的记录. 最终达到的结果就像"表2"一样.
 高手门帮帮忙.......

解决方案 »

  1.   

    select ID=ID1 from 表1 where ID1 is not null
    union all
    select ID2 from 表1 where ID2 is not null
      

  2.   

    create table T(ID1 varchar(10), ID2 varchar(10))
    insert T select      'String1',       'String2'
    union all select       'String3',       Null
    union all select       'String4',       'String5'
    union all select       Null,          'String6'select * from 
    (
    select ID1 from T
    union all
    select ID2 from T
    )a 
    where a.ID1 is not null
    order by a.ID1 --result
    ID1        
    ---------- 
    String1
    String2
    String3
    String4
    String5
    String6(6 row(s) affected)