首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请教select查询语句怎么调用存储过程

2012-09-07 
请问select查询语句如何调用存储过程?如题:table1表:字段a1,a2,a3存储过程Pro1 a1,a2,a3(本来是函数,可以

请问select查询语句如何调用存储过程?
如题:

table1表:字段a1,a2,a3
存储过程Pro1 a1,a2,a3(本来是函数,可以实现,但由于查询表不确定要实现动态执行,所以只能改成存储过程)
变量@count
select @count=sum(pro1 a1,a2,a3) from table1
我要实现这样的,请问如何实现?


[解决办法]
非常遗憾告诉你存储过程这样不行,只能采用这种方式变通
insertt #TableName
exec pro_ProcedureName
[解决办法]
好像不行,期待高手
建议你还是想怎么改函数来解决吧
[解决办法]
函数的话可以直接使用。

如果是存储过程的话,可以用游标逐行循环数据。
[解决办法]

SQL code
create table table1(a1 int ,a2 int,a3 int)insert table1select 1,3,4 union allselect 2,3,4 union allselect 6,7,8 union allselect 9,1,6 union allselect 12,13,16select * from table1/*a1          a2          a3----------- ----------- -----------1           3           42           3           46           7           89           1           612          13          16*/go--随便写个存储过程create proc Proc_table1 (@a1 int ,@a2 int, @a3 int)asbegin    select 2*@a1+3*@a2+@a3endgocreate table #t(asum int)declare my_cursor cursor forselect a1,a2,a3 from table1open my_cursordeclare @a1 int, @a2 int,@a3 int fetch next from my_cursor into @a1,@a2,@a3while(@@fetch_status=0)  begin    insert into #t exec Proc_table1 @a1,@a2,@a3 --执行存储过程    fetch next from my_cursor into @a1,@a2,@a3  endclose my_cursordeallocate my_cursorselect sum(asum) from #t/*179*/drop table #t
[解决办法]
openrowset
[解决办法]
SQL code
SELECT  *FROM    OPENROWSET('SQLOLEDB', 'SERVER=sss;uid=sa;pwd=123;Database=db ', 'exec sp') AS a 

热点排行