ConfluentData wrote:
I think we're on the verge of cracking this nut, but unfortunately I'm getting null reference with this code:
(...)
It looks like the null reference is ocurring on the "Joiner2" predicate with those nulls in there. Without them, I get an error telling me there's not table aliased for "E2". Any ideas?
The second subquery uses the adapter constructor, so you should remove the null values. You specify a relation, and an alias in the first subquery. The relation though hasn't an alias set for either entity, so you will get a FROM clause without aliases for the tables, though you use an alias 'E2' for the field in the where clause, which can't find the table, as 'E2' isnt in the first subquery's FROM clause.
However! , I now see you don't need the first subquery. Your original query:
SELECT *
FROM TBL_EMPLOYEE E
WHERE E.EMPLOYEE_ID =
(
SELECT EMPLOYEE_ID
FROM TBL_EMPLOYEE E3, TBL_JOB J
WHERE E3.EMPLOYEE_ROW_ID = J.EMPLOYEE_ROW_ID
AND
J.JOB_ROW_ID = @JobID
)
AND E.EFFECTIVE_DATE IN
(
SELECT MAX(E2.EFFECTIVE_DATE)
FROM TBL_EMPLOYEE E2
WHERE E2.EFFECTIVE_DATE <= GETDATE()
AND
E2.EMPLOYEE_ID = E.EMPLOYEE_ID
)
can also be written as:
SELECT *
FROM TBL_EMPLOYEE E INNER JOIN TBL_JOB J
ON E.EMPLOYEE_ROW_ID = J.EMPLOYEE_ROW_ID
WHERE J.JOB_ROW_ID = @JobID
AND E.EFFECTIVE_DATE IN
(
SELECT MAX(E2.EFFECTIVE_DATE)
FROM TBL_EMPLOYEE E2
WHERE E2.EFFECTIVE_DATE <= GETDATE()
AND
E2.EMPLOYEE_ID = E.EMPLOYEE_ID
)
Which simply requires you to pass the relation to the GetMulti, and a simple fieldcomparevalue predicate on jobid + the second subquery you have now. No need for aliasing E and J.