表值函数:
ALTER FUNCTION getTable( )
RETURNS TABLE AS
RETURN ( select * from tb)
取值:select * from getTable( )
标量函数:
ALTER FUNCTION [dbo].[CamOnlineAverage] (
@projId INT ,
@startDate DATETIME ,
@endDate DATETIME
)
RETURNS Float AS
Begin
DECLARE @result FLOAT,@s int,@t int;
SELECT @s=SUM(SumTime) ,@t=SUM(TotalTime) FROM dbo.tb_CamOnlineDetail(@projid,@startDate,@endDate)
IF(@t=0)begin RETURN 0.0 END
RETURN @s*100.0/@t
End
取值:select CamOnlineAverage(1212,‘2016-5-5‘,‘2016-8-8‘)
时间: 2024-10-01 04:36:50