各位大牛,请教个问题,如何获取结果集的字段名。如数据库中已经有个存储过程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?
谢谢!
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?
谢谢!
insert tb exec sp_test(@iid int)
from
openrowset( 'SQLOLEDB', '服务器名'; '用户名'; '密码','exec 数据库名.dbo.存储过程名')
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谢谢!
from openrowset( 'SQLOLEDB', 'server'; 'sa'; 'password','exec db.dbo.sp_test(3)') select name from syscolumns where id=object_id('newtab')drop table newtab
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谢谢各位。