I have an input db2 table with two elements: loan_number, debt_to_income; this table's name is #Input_Table. I am trying to run a test the function by running a SQL program against this table. The problem is that the function's element is not being recognized in the SQL program for some reason, maybe I have been looking at to long? I need to validate that the output in the table will output in a order by the debt_to_income field.
Here is the function code:
ALTER FUNCTION [dbo].[FN_DTI_BANDS]
(
-- the parameters for the function here
@FN_DTI_Band decimal(4,3)
)
RETURNS varchar(16)
AS
BEGIN
declare @Return varchar(16)
select @Return =
Case
when @FN_DTI_Band is NULL then ' Missing'
WHEN @FN_DTI_Band = 00.00 then ' Missing'
When @FN_DTI_Band < = 0.31 then 'Invalid'
When @FN_DTI_Band between 0.31 and 0.34 then '31-34'
When @FN_DTI_Band between 0.34 and 0.38 then '34-38'
When @FN_DTI_Band >= 0.38 then '38+'
else null end
-- Return the result of the function
RETURN @Return
END
Here is the T-SQL test program:
SELECT loan_number,dbo.FN_DTI_BANDS(debt_to_income)as FN_DTI_Band
from #Input_table
SELECT COUNT(*), FN_DTI_Band
FROM #Input_table
GROUP BY FN_DTI_Band
ORDER BY FN_DTI_Band
Here is the error:
Msg 207, Level 16, State 1, Line 7
Invalid column name 'FN_DTI_Band'.
Msg 207, Level 16, State 1, Line 5
Invalid column name 'FN_DTI_Band'.
Can someone help me spot what I am overlooking? Thank you!