Need to use query column value in nested subquery
- by Dustin
It seems I cannot use a column from the parent query in a sub query.
How can I refactor this query to get what I need?
dbo.func_getRelatedAcnts returns a table of related accounts (all children from a given account). Events and Profiles are related to accounts.
SELECT COUNT(r.reg_id)
FROM registrations r JOIN profiles p ON (r.reg_frn_pro_id = p.pro_id)
JOIN events e ON (r.reg_frn_evt_id = e.evt_id)
WHERE evt_frn_acnt_id NOT IN (SELECT * FROM dbo.func_getRelatedAcnts(p.pro_frn_acnt_id))