• Something like:

    SELECT e.EID FROM #EventLog e

    INNER JOIN #LD l

    ON e.SourceID = l.TranId

    WHERE l.TranID = 1234

    AND e.SourceType = 3004

    UNION ALL

    SELECT e.EID FROM #EventLog e

    INNER JOIN #LD l

    ON e.SourceID = l.LoanId

    WHERE l.TranId = 1234

    AND e.SourceType = 3001

    UNION ALL

    SELECT e.EID FROM #EventLog e

    INNER JOIN #PD p

    ON e.SourceID = p.PDID

    WHERE p.TranID = 1234

    AND e.SourceType = 3015

    You can try to do it in one query with some outer joins and case statements in the ON clauses, but this way just looks cleaner. You can switch from union all to union if you want to filter out duplicates, and add any fields from #EventLog you want to select.