34,696
社区成员
这是我的函数,输入两个变量,@InputDate是当前的日期,@account_no是账户号,输出5个工作日的总交易量, [dbo].[Getworkday](@InputDate,5)这个函数可以返回5个工作日前的日期,我发现这个函数永远返回的是null,正常查这个账户和时间段是有数据的,求大神解答
CREATE function Getworkday_txnsum(@InputDate DATE,@account_no nvarchar)
returns float
BEGIN
DECLARE @ResultDate DATE = @InputDate
DECLARE @dailysum float
Declare @acc_id nvarchar= @account_no
DECLARE @lookbackdate date
set @lookbackdate = [dbo].[Getworkday](@InputDate,5)
select @dailysum = sum(TRANSACTION_AMOUNT_IN_HKD)
from [dbo].[ALH105PT_updated]
where Risk_Type = 'HPH'
and TRANSACTION_AMOUNT_IN_HKD >= 2400
and transaction_cdi_code = 'D'
and TRANSACTION_ACCOUNT_NO = @acc_id
and transaction_date between @lookbackdate and @ResultDate
group by TRANSACTION_ACCOUNT_NO
return @dailysum
end