--有输入参数的存储过程--
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
--调用方法--
declare @count int
exec @count=MyFunction 2
print @count
--返回值为表的函数--
Create function GetFunctionTable
(@newsid int)
returns table
as
return
(select * from Comment where NewsID=@newsid)
--返回值为表的函数的调用--
select * from GetFunctionTable(2)