出處:http://www.jb51.net/article/54730.htmsql
--有輸入參數的存儲過程--
create
proc GetComment
(@commentid
int
)
as
select
*
from
Comment
where
CommentID=@commentid
--有輸入與輸出參數的存儲過程--
create
proc GetCommentCount
@newsid
int
,
@
count
int
output
as
select
@
count
=
count
(*)
from
Comment
where
NewsID=@newsid
--返回單個值的函數--
create
function
MyFunction
(@newsid
int
)
returns
int
as
begin
declare
@
count
int
select
@
count
=
count
(*)
from
Comment
where
NewsID=@newsid
return
@
count
end
MyFunction
1
--返回值爲表的函數--
Create
function
GetFunctionTable
(@newsid
int
)
returns
table
as
return
(
select
*
from
Comment
where
NewsID=@newsid)
調用方式:
select
*
from
GetFunctionTable(2)