I'm trying to do something like this...
SELECT lc.Location, count(h.empID) as 'Count', lu.LBL
FROM swam.lookup lu
LEFT JOIN swam.empTable h
ON CASE
WHEN lu.sac is null
THEN lu.POS = h.POS
ELSE (
lu.POS = h.POS
and
lu.sac = h.sac)
INNER JOIN swam.Locations lc
ON h.LocationID = lc.LocationID
GROUP BY lc.Location, lu.LBL
ORDER BY lc.Location
So, if lu.sac is null, then only join the tables on one common column. If it's not null, then it has to use both POS and SAC to join.
Is this possible?