I know that there are several questions around this exception on SO, but nothing seen that helps me.
I have 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
previousClaimsByFiData
is a Table-Valued-Function that returns all previous records. You can find it here if you're interested.
Now i want to find all claims that have previous claims in the last 90 days with a maxActionCode IN(8, 23, 24).
What i've also tried was 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 a "The maximum recursion 100 has been exhausted before statement completion"
-Exception.
Why do i get those exceptions and how to avoid them?
Thank you
EDIT: asked another question which is reduced on the main problem. I can delete this when i get an answer there.
UPDATE: Marc answered a simplified question according to this here. So the way to go is Cross Apply. But now i have the next problem what i've already mentioned above. I get a "The maximum recursion 100 has been exhausted before statement completion" Error after a few seconds. I dont know where to add the OPTION (MAXRECURSION 0) because i get a "Incorrect Syntax" if i try to add it in the Inline-TVF.
My current query is:
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: the solution was to add the OPTION (MAXRECURSION 0) to the end of the SELECT Statement.