select * from (exec (+@procName+))

解决方案 »

  1.   

    create table tab(
    ...
    )insert tab exec procNameselect * from tab
      

  2.   

    --不能直接的查询.但我提供两个办法.
    1.
    create table #temp_tb(name varchar(8))
    insert #temp_tb exec procname
    select * from #temp_tb
    drop table #temp_tb
    2.
    SELECT a.*FROM OPENROWSET('SQLOLEDB','服务器名称';'用户名';'密码','exec procname') AS a--这样就可以直接的查询存储过程的结果集了.
      

  3.   

    临时表和OPENROWSET的速度如何?
      

  4.   

    OPENROWSET与临时表相比,性能如何?
      

  5.   

    if exists(select * from sysobjects where name = table_name)
        select * from table_name
    else
        begin
            print '不存在'
        end