HERE IS THE FUNCTION:
ALTER FUNCTION dbo.FN_GET_QUARTER
-- the parameters for the function here
(
@FN_Qtr_date datetime
)
RETURNS INT
AS
BEGIN
RETURN datepart(qq,@FN_Qtr_date)
END
HERE IS THE SQL REPORT:
IF(SELECT(OBJECT_ID('TEMPDB..#T1'))) IS NOT NULL DROP TABLE #T1
SELECT L_NUMBER, LAST_MAINTENANCE_DATE,
dbo.FN_FICO_BANDS (LAST_MAINTENANCE_DATE) AS FN_Qtr_date
INTO #T1
FROM OPENQUERY(SrvLink, '
SELECT LOAN_NUMBER,LAST_MAINTENANCE_DATE
FROM BDE.loan_V
FETCH FIRST 1000 ROWS ONLY WITH UR ')
GO
SELECT COUNT(*), FN_Qtr_date
FROM #T1
GROUP BY FN_Qtr_date
ORDER BY FN_Qtr_date
Results:
L count FN_Qtr_Date
150 Invalid
355 Invalid
I am not sure what I am doing wrong..