CREATE FUNCTION [dbo].
[f_DailyIncome]
(
@userId int,
@date date
)
RETURNS decimal(
18,
2)
AS
BEGIN
declare @income decimal(
18,
2);
select @income = ISNULL(
sum(uc.
[TotalFee]*bcl.
[Percent]),
0)
from Channel_User
as cu
left join Back_Purse
as bp
on bp.OwnerId
= cu.LeaderId
left join Back_ChannelLevel bcl
on cu.ChannelLevelId
=bcl.Id
left join [Users] as u
on cu.ChannelId
=u.ChannelId
left join [User_Consumptions] as uc
on uc.UserId
=u.Id
where cu.UserId
=@userId and uc.
[Status]=3 and uc.AddDate
=@date;
-- Return the result of the function
RETURN @income;
END
GO
转载于:https://www.cnblogs.com/zoro-zero/p/5548524.html
相关资源:很全面的SQL函数及例子
转载请注明原文地址: https://mac.8miu.com/read-63531.html