Can I use a previous OUTER APPLY in a subsequent OUTER APPLY

Bobby P 221 Reputation points

So I have an [OuterApply1] which SELECTs TOP (1) from a ROW_NUMBER. I would then like to use that [OuterApply1] in another subsequent [OuterApply2] to filter based on what is returned in the [OuterApply1].

Is this possible?

Can I do that?

Thanks for your review and am hopeful for a reply.

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,544 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 100.7K Reputation points MVP

    It would have helped if you had a supplied an example to clarify what you are talking about. But, yes, you can do:

       SELECT ...  
       FROM  tbl t  
       OUTER APPLY (...) AS A  
       OUTER APPLY (SELECT that refers to A here) AS B  

    `Although, I am not fully sure that is what you have in mind.

    0 comments No comments