Multiple Part ID Cannot Be Linked

I know that on this exception there are several questions about this exception, but nothing is visible that helps me.

I have the following query giving me a "Multi-part identifier 'claim.fiData' could not be bound"-Exception:

SELECT  claim.idData FROM tabData as claim 
 INNER JOIN dbo._previousClaimsByFiData(claim.fiData) AS prevClaim 
 ON prevClaim.idData=claim.fiData 
GROUP BY claim.idData
HAVING(prevClaim.fiMaxActionCode IN (8, 23, 24) and 
prevClaim.Repair_Completion_Date >= DATEADD(day,-90,prevClaim.Repair_Completion_Date))
ORDER BY claim.idData

previousClaimsByFiDatais a table-value-function that returns all previous records. You can find it here if you are interested. Now I want to find all the claims that had previous claims in the last 90 days with maxActionCode IN (8, 23, 24).

What I also tried is the following:

SELECT  count(*) FROM tabData as claim 
where exists(
 select 1 from dbo._previousClaimsByFiData(claim.fiData)as prevClaim where 
  prevClaim.fiMaxActionCode IN(8, 23, 24)and 
  prevClaim.Repair_Completion_Date >= DATEADD(day,-90,claim.Repair_Completion_Date)
)

But that gives me an "The maximum recursion 100 has been exhausted before statement completion"-Exception.

Why do I get these exceptions and how to avoid them?

thank

EDIT: asked another question that comes down to the main problem. I can remove this when I get a response.

UPDATE: . , Cross Apply. , . " 100 " . , OPTION (MAXRECURSION 0), " ", Inline-TVF.

:

SELECT  claim.idData FROM tabData  claim 
    CROSS APPLY dbo._previousClaimsByFiData(claim.fiData)AS tvfData 
GROUP BY claim.idData,claim.Repair_Completion_Date,tvfData.Repair_Completion_Date,tvfData.fiMaxActionCode
HAVING(tvfData.fiMaxActionCode IN (8, 23, 24) and 
tvfData.Repair_Completion_Date >= DATEADD(day,-90,claim.Repair_Completion_Date))
ORDER BY claim.idData


UPDATE: , OPTION (MAXRECURSION 0) SELECT.
+3
1

, OPTION (MAXRECURSION 0) SELECT. :

SELECT claim.idData,claim.Repair_Completion_Date,prevClaim.Repair_Completion_Date,prevClaim.fiMaxActionCode FROM tabData  claim 
    CROSS APPLY dbo._previousClaimsByFiData(claim.fiData)AS prevClaim 
GROUP BY claim.idData,claim.Repair_Completion_Date,prevClaim.Repair_Completion_Date,prevClaim.fiMaxActionCode
HAVING(prevClaim.fiMaxActionCode IN (8, 23, 24) and 
prevClaim.Repair_Completion_Date >= DATEADD(day,-90,claim.Repair_Completion_Date))
ORDER BY claim.idData
OPTION (MAXRECURSION 0)

( , 23000 > 11Mio rec), .

UPDATE: (< 4 ) EXISTS CROSS APPLY:

  SELECT     idData
    FROM     tabData AS claim
    WHERE    fiProductType=1 and fiClaimStatus IN(1,5,7,8,9) AND EXISTS
         (SELECT idData
          FROM   dbo._previousClaimsByFiData(claim.fiData) AS prevClaim
          WHERE  (fiProductType = 1) AND (fimaxActionCode IN (8, 23, 24)) 
          AND (Repair_Completion_Date >= DATEADD(dd, - 90, DATEADD(dd, DATEDIFF(dd,0, claim.Repair_Completion_Date), 0))) 
          AND (Repair_Completion_Date <= claim.Repair_Completion_Date)) 
  order by claim.idData
  OPTION (MAXRECURSION 0)
+1

Source: https://habr.com/ru/post/1770699/


All Articles