'The multi part identifier could not be bound for a hidden column of OUTER APPLY
This issue still not been resolved, please advise !
I've seen similar cases on SO, but I don't find a solution for my problem.
If I have a query like this, and when I want to use BCol2 from table t ( union of TAB1 and TAB2 ) to validate a condition ( without taking into consideration the first TOP 1 applied in tblB ). I have the following error
the multi part identifier BCol2 could not be bound
SELECT tblA.Col, tblB.BCol2, tblC.CCol
FROM tblA
OUTER APPLY (SELECT TOP 1 BCol2
FROM ( SELECT BCol2 from TAB1 WHERE (condition) UNION SELECT BCol2 FROM TAB2 WHERE (condition)) t
ORDER BY BCol2) tblB
INNER JOIN tblC on tblC.ColNameC = tblA.ColNameA
WHERE
t.BCol2 = (condition);
Any idea pls ?
Solution 1:[1]
SELECT tblA.Col, tblB.BCol2, tblC.CCol
FROM tblA
OUTER APPLY
(
SELECT TOP 1 t.BCol2
FROM
(
SELECT BCol2 from TAB1 WHERE (condition)
UNION
SELECT BCol2 FROM TAB2 WHERE (condition)
) t
ORDER BY t.BCol2
) tblB
INNER JOIN tblC on tblC.ColNameC = tblA.ColNameA
WHERE tblB.BCol2 = (condition);
please try this one
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sergey |
