各位大牛,请教个问题,如何获取结果集的字段名。如数据库中已经有个存储过程sp_test:
create proc sp_test(iid int)
as
begin
     select 1 as name,
            2 as age,
            3 as total
end那我如何用sql语句存储过程sp_test的返回结果的字段名,即如何获取name,age,total?
谢谢!

解决方案 »

  1.   

    create table tb(....)
    insert tb exec sp_test(@iid int)
      

  2.   

    select * 
    from 
    openrowset( 'SQLOLEDB', '服务器名'; '用户名'; '密码','exec 数据库名.dbo.存储过程名') 
      

  3.   

    改正的存储过程:
    create proc sp_test(@iid int)
    as
    begin
    select 1 as name,
    2 as age,
    3 as total
    end
    那么我并不是想通过执行存储过程exec sp_test 1 来获取结果:
        |  name  |  age   |  total
    1   |  1     |  2    |   3
    而是想有没有其他sql语句仅仅获取name,age,total 这三个字段的字段名称而已,而非其值,即目标结果为:
    name
    age
    total谢谢!
      

  4.   

    select * into newtab
    from openrowset( 'SQLOLEDB', 'server'; 'sa'; 'password','exec db.dbo.sp_test(3)') select name from syscolumns where id=object_id('newtab')drop table newtab
      

  5.   

    谢谢sql_sf 的帮助,但是chuifengde的代码才完全的
    select * into newtab
    --存储过程不带():from openrowset( 'SQLOLEDB', 'server'; 'sa'; 'password','exec db.dbo.sp_test(3)') 
    from openrowset( 'SQLOLEDB', 'server'; 'sa'; 'password','exec db.dbo.sp_test 3 ')--sql_sf要加上这句
    select name from syscolumns where id=object_id('newtab')drop table newtab谢谢各位。