select id1 from employee ..
/*
id1
2
*/
select name from hospital ..
/*
name 
王八
*/我想变成这样的
/*
id1    name
2      王八
*/能行吗?

解决方案 »

  1.   


    --> 测试数据: @employee
    declare @employee table (id1 int)
    insert into @employee
    select 2
    --> 测试数据: @hospital
    declare @hospital table (name varchar(4))
    insert into @hospital
    select '王八'select * from @employee cross join @hospital
    /*
    id1         name
    ----------- ----
    2           王八
    */
      

  2.   

    select idl ,'' as name from employee 
    union 
    select '' as idl,name from hospital
      

  3.   

    上面的SQL好像有问题,你的两个表应该是有关联关系的,还是要用JOIN
      

  4.   

    --> 测试数据: @employee
    declare @employee table (id1 int)
    insert into @employee
    select 2
    --> 测试数据: @hospital
    declare @hospital table (name varchar(4))
    insert into @hospital
    select '王八'select * from @employee,@hospitalid1         name
    ----------- ----
    2           王八(1 行受影响)