表a:
time     input
08:55    aaa
09:30    bbb表b:
time     output
12:05    ccc
23:11    ddd现想得到一合并的集合,即:TIME1    INPUT1 OUTPUT1
08:55    aaa
09:30    bbb
12:05           ccc
23:11           ddd用select a.time TIME1,input INPUT1,'' OUTPUT1 from a union select b.time TIME1,'' IMPUT1,output OUTPUT1 from b order by TIME1可是报错说两个select集类型不同,貌似''与a.input及b.output长度不同(虽然都是字符型)
那么,我该怎么解决呢,谢谢

解决方案 »

  1.   

    select a.time TIME1,input INPUT1,NULL OUTPUT1 from a union select b.time TIME1,NULL IMPUT1,output OUTPUT1 from b order by TIME1
    就是拿NULL代替''
      

  2.   

    create table a
    (
    time varchar(10),
    input varchar(10)
    )
    insert into a
    select '08:55','aaa' union all
    select '09:30',   'bbb'
    select * from a
    create table b
    (
    time varchar(10),
    output varchar(10)
    )
    insert into b
    select '12:05',    'ccc' union all
    select '23:11',    'ddd'
    select * from bselect a.time TIME1,input INPUT1,'' OUTPUT1 from a union select b.time TIME1,'' IMPUT1,output OUTPUT1 from b order by TIME1楼主是SQl SERver 2000么?
      

  3.   

    a.input及b.output长度不同(虽然都是字符型)楼主用的是char?
      

  4.   

    select a.time TIME1,input INPUT1,'' OUTPUT1 from a 
    union 
    select b.time TIME1,
    cast('' as A表的input列的数据类型),
    cast(output as A表的output列的数据类型) 
    from b order by TIME1
      

  5.   

    select a.time TIME1,input INPUT1,NULL OUTPUT1 from a union all select b.time TIME1,NULL IMPUT1,output OUTPUT1 from b order by TIME1
      

  6.   

    select a.time TIME1,input INPUT1,'' OUTPUT1 from a 
    union select b.time TIME1,'' INPUT1,output OUTPUT1 from b order by TIME1
    这个报错的话,很可能就是两个集合的某些字段长度不同造成的可以这样解决
    建立一个临时表,把其字段名、类型、长度等确定
    再把两集合都插入此临时表