Are these the same?
INNER JOIN dbo.ReportingLevels rl ON e.ei_CompanyID = rl.rl_CompanyId
AND e.ei_Level = rl.rl_index
AND EXISTS (SELECT * FROM @ReportingLevelId rlid
WHERE rlid.[reportLevelName] = rl.[rl_name])
AND EXISTS (SELECT * FROM @ReportingLevelId rlid
WHERE rlid.[companyid] = rl.[rl_CompanyId])
And here is the second.
INNER JOIN dbo.ReportingLevels rl ON e.ei_CompanyID = rl.rl_CompanyId
AND e.ei_Level = rl.rl_index
AND EXISTS (SELECT * FROM @ReportingLevelId rlid
WHERE rlid.[reportLevelName] = rl.[rl_name]
AND rlid.[companyid] = rl.[rl_CompanyId]))
I am thinking these are the same, but I got a weird result once when I used a similar variation of this.
No, they are not. The first would select a row if rl_name and rl_CompanyId were present in table @ReportingLevelId, but not necessarily in the same row. The second requires those values to be present in the same row.