SQL儲存過程中呼叫返回表型別引數的函式的一種實現

2021-04-20 09:02:14 字數 854 閱讀 6669

--函式

--返回型別:表(table)

create function funtest

@para1 type(length),

@para2 type(length),

@paran type(length)

return @table table

col1 type(length),

col2 type(length),

coln type(length)

asbegin

--【函式實體】

--填充表資料內容

--……insert into @table……

--……update @table set……

return

end--儲存過程

--返回資料表

create proc proctest

@para1 type(length),

@para2 type(length),

@paran type(length)   

as--表變數定義

declare @table table

col1 type(length),

col2 type(length),

coln type(length)

declare @p1 type(length)

declare @pn type(length)

begin

【儲存過程實體】

insert into @table select * from funtest(引數) where (條件)《與sql查詢語句一致》

select * from @table

end

儲存過程中呼叫儲存過程

use northwind go 儲存過程1 功能 通過員工firstname inputempfirstname 獲得 員工id outid if exists select name from sysobjects where name p getempleeidbyname and type ...

C 執行SQL儲存過程返回表

參考參考 建立乙個名為get的儲存過程 先定義兩個引數 其中 count為輸出引數 sql語句中 第一句返回該錶所有內容,第二句 返回表的行數,並把值賦給輸出引數 create procedure get name varchar 50 count int output asselect from ...

C 執行SQL儲存過程返回表

參考參考 建立乙個名為get的儲存過程 先定義兩個引數 其中 count為輸出引數 sql語句中 第一句返回該錶所有內容,第二句 返回表的行數,並把值賦給輸出引數 create procedure get name varchar 50 count int output asselect from ...