I have a table with a clientID, employeeID and, a code. I want to join that to another table which will contain the clientID, the code and possibly the employeeID. If the employeeID does not exist, there will be a default record which will contain clientID and the code. The employeeID would be NULL
FROM #Temp tx
INNER JOIN letter l
tx.ClientID = l.ClientID
AND tx.Code = l.Code
CASE WHEN EXISTS(select id from lett where ClientID = @ClientID and Code = tx.Code and EmployeeID = tx.Employee) THEN
---AND tx.EmployeeID = l.EmployeeID---
END
That's what I'm looking for. Any thoughts? I don't want to use dynamic sql. Thanks
FROM #Temp tx
INNER JOIN letter l
tx.ClientID = l.ClientID
AND tx.Code = l.Code
CASE WHEN EXISTS(select id from lett where ClientID = @ClientID and Code = tx.Code and EmployeeID = tx.Employee) THEN
---AND tx.EmployeeID = l.EmployeeID---
END
That's what I'm looking for. Any thoughts? I don't want to use dynamic sql. Thanks