我有一个存储过程是这样写的:
  Create procedure GetDetail_spas 
   begin
     select t1.lastname,
            t1.firstname,
            t1.country,
            t1.state,
            t1.city
     from table t1
    union 
     select t2.lastname,
            t2.firstname,
            t2.country,
            t2.state,
            t2.city
      from #Specified t2          
   end 这样执行存储过程后,实际上返回的就是个table,我怎么能接收这个table呢?
比如: exec GetDetail_sp
接着我想查出某个lastname的信息,select * from ?, 这个地方该怎么写?

解决方案 »

  1.   

    楼主事先要知道存储过程返回结果集都有什么字段,然后创建个临时表create table #temp(...字段...)insert into #temp exec 过程名 参数select ... from #tempdrop table #temp试试。
      

  2.   

    可以使用表值函数
    create FUNCTION [dbo].[f_GetTable]()
    RETURNS TABLE
    AS
    RETURN(
    select 1 Id,'张三' name
    union all select 2 Id,'李四' name
    )查询
    select * from [dbo].[f_GetTable]()