函数未从变量返回值

时间:2019-07-03 04:47:15

标签: sql-server tsql

IF (@crncy_code = 'JMD') BEGIN
    SELECT @total = isnull(sum(balance),0)
    FROM [PROD_EIMDW_BOJ_REPORTS].[BOJOWN].[LOANS_TAB] blt
    WHERE currency = 'JMD'
    AND chrge = 'N' -- not charged off                  
    AND dpd <= @p_days_past_upper_range
    AND dpd >= @p_days_past_lower_range                 
    AND NOT EXISTS(SELECT 1 FROM [BOJOWN].[LOANS_EXCLUSION] WHERE acid = blt.acid)                          
    AND NOT EXISTS (SELECT acid FROM  [PROD_EIMDW_Archive].[ARCHOWN].[FINCL10_ALR]  WHERE BANK_ID= @bank_id  AND  acct_label = 'MUNDO' AND ACTIVE_FLAG = 'Y'  AND DELETE_FLAG='N' AND acid = blt.acid)

    SELECT @other_sum = isnull(sum(balance),0)
    FROM [PROD_EIMDW_BOJ_REPORTS].[BOJOWN].[LOANS_TAB] blt
    WHERE currency = 'JMD'
    AND chrge = 'N' -- not charged off
    AND dpd <= @p_days_past_upper_range
    AND dpd >= @p_days_past_lower_range 
    AND NOT EXISTS (SELECT acid FROM  [PROD_EIMDW_Archive].[ARCHOWN].[FINCL10_ALR]   WHERE BANK_ID= @bank_id  and DELETE_FLAG='N' AND acct_label = 'MUNDO' AND ACTIVE_FLAG = 'Y' AND acid = blt.acid)
    AND EXISTS (SELECT 1 FROM [PROD_EIMDW_BOJ_REPORTS].[BOJOWN].[LOANS_EXCLUSION] WHERE acid = blt.acid)    

    set @loanCount = @total + @other_sum

当我运行函数时,它不返回两个变量的和,而仅返回存储在第一个变量中的值。另外请注意,当我在函数外部运行语句时,还可以。下面是return语句:

RETURN isnull(@loanCount,0)

1 个答案:

答案 0 :(得分:0)

我不确定您的查询出了什么问题,但是我会这样简化它:

ERROR NullInjectorError: StaticInjectorError(AppModule)[InjectionToken API_BASE_URL]:

此查询返回正确的结果吗?