开发者

udf not returning data correctly in t-sql programming

HERE IS THE FUNCTION:

ALTER FUNCTION dbo.FN_GET_QUARTER
 -- the parameters for the function here
(
  @FN_Qtr_date  datetime 
)

RETURNS 开发者_如何学GoINT
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..


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜