當前位置:首頁 » 服務存儲 » 存儲過程中怎麼用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