我有表a,现工作是把select col001 from a where 条件1的结果填到execl的A列
select col001 from a where 条件2填到execl的B列,以此类推一共有20种条件,现请问能否把这20个条件写到一起一次查询到20列,一次复制到execl里

解决方案 »

  1.   

    select id=identity(int1,1) , col001 into tb1 from a where 条件1
    select id=identity(int1,1) , col002 into tb2 from a where 条件2
    ......
    select id=identity(int1,1) , col020 into tb20 from a where 条件20假设数量一样多.
    select tb1.col001,tb2.col002,...tb20.col020 
    from tb1,tb2,...tb20
    where tb1.id = tb2.id and tb1.id = tb3.id ... and tb1.id = tb20.id如果数量不一样多.使用全连接.
    select isnull(tb1.col001,null) , isnull(tb2.col002,null) ... , isnull(tb20.col020)
    from tb1 
    full join tb2 on tb1.id = tb2.id
    full join tb3 on tb1.id = tb3.id
    ......
    full join tb20 on tb1.id = tb20.id