create proc storeproc @c varchar(20)
select * from (
select a as aa,b as bb from tablea where a=@c
union
select c as aa,cc as bb from tableb where c=@c
) order by aa
union 的两个表字段的数据类型都一样的
是要建个存储过程,@c是传入参数
这样用好像不行啊,可我必须union后在排序,而且必须有参数
错误:order by 附近由于法错误

解决方案 »

  1.   

    order by tablea.aa ?
      

  2.   

    create proc storeproc 
    @c varchar(20)
    as
    select a as aa,b as bb from tablea where a=@c
    union all
    select c as aa,cc as bb from tableb where c=@c
    order by aa
      

  3.   

    create proc storeproc @c varchar(20)
    as
    select * from (
    select a as aa,b as bb from tablea where a=@c
    union
    select c as aa,cc as bb from tableb where c=@c
    ) order by aa
    少了个as
      

  4.   

    : zjsen(离开中...) ( ) 信誉:98 的对了,给分
      

  5.   

    create proc storeproc @c varchar(20)
    as (
    select a as aa,b as bb from tablea where a=@c
    union
    select c as aa,cc as bb from tableb where c=@c
    ) order by aa