views:

14

answers:

2

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..

A: 

dbo.FN_FICO_BANDS (LAST_MAINTENANCE_DATE) AS FN_Qtr_date

If you're going to use the function on LAST_MAINTENANCE_DATE, you need to use: dbo.FN_Qtr_Date(LAST_MAINTENANCE_DATE) AS YourQuarter

Vidar Nordnes
+1  A: 

The first thing that jumps out at me is that you're calling dbo.FN_FICO_BANDS instead of dbo.FN_GET_QUARTER

Toby
Duh! I think I need to take a break! That is the problem alright! Thanks Martin, sorry for such a dumb question/ error
JMS49