iT邦幫忙

0

請問如何執行完SP 然後select * from (execute sp)結果

請問如何執行完SP
然後select * from (execute sp)結果

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
暐翰
iT邦大師 1 級 ‧ 2018-03-13 10:23:58
最佳解答

假如資料量不大,個人常用"全域temp table"方式

注意:

多人執行情況下,會可被其他session讀取

舉例:

CREATE PROCEDURE Sample_Procedure 
    @param1 int = 20,
    @param2 int  
AS
	with temp_table as (
		SELECT @param1 id1,@param2  id2
	)
	select * into ##temp_table from temp_table;
RETURN 0 

--執行sp
execute Sample_Procedure @param2=10

--使用全域temp table來讀取資料
select * from ##temp_table
where id2 = 10

結果:


想更了解其他用法可以看 預存程序的結果如何再利用?

謝謝!!

我要發表回答

立即登入回答