当前位置:首页 » 服务存储 » 存储过程中怎么用select
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

存储过程中怎么用select

发布时间: 2023-03-23 13:47:05

1. 如何在SELECT语句中调用存储过程的结果

在SELECT语句中调用存储过程的结果:

直接调用好像不可以!不过你可以把存储过程中的内容插入一张临时表,然后再从临时表中调用!

sql">createtabletable1(a1int,a2int,a3int)
inserttable1
select1,3,4unionall
select2,3,4unionall
select6,7,8unionall
select9,1,6unionall
select12,13,16

select*fromtable1
/*
a1a2a3
---------------------------------
134
234
678
916
121316
*/

go
--随便写个存储过程
createprocProc_table1
(@a1int,@a2int,@a3int)
as
begin
select2*@a1+3*@a2+@a3
end

go
createtable#t(asumint)
declaremy_cursorcursorfor
selecta1,a2,a3fromtable1
openmy_cursor
declare@a1int,@a2int,@a3int
fetchnextfrommy_cursorinto@a1,@a2,@a3
while(@@fetch_status=0)
begin
insertinto#texecProc_table1@a1,@a2,@a3--执行存储过程
fetchnextfrommy_cursorinto@a1,@a2,@a3
end
closemy_cursor
deallocatemy_cursor
selectsum(asum)from#t
/*
179
*/
droptable#t

2. 存储过程中if里怎么写select语句

1
if exists (select 1 from test where xxxxx)
begin
end
2
case when a=xxx then 'xxx' else '0' end