Hi @David Fetrow ,
Please try the following solution. It is using XQuery and Quantified Expressions.
And it is generic, meaning if the Organization table has more columns to check like AltNTimekeeper, it will work without any T-SQL modification.
SQL
-- DDL and sample data population, start
DECLARE @employee TABLE (id INT PRIMARY KEY, employeeID INT);
INSERT INTO @employee (id, employeeID) VALUES
(1, 3456),
(2, 5689);
DECLARE @Organization TABLE (id INT PRIMARY KEY, timekeeper INT, Alt1Timekeeper INT, Alt2Timekeeper INT);
INSERT INTO @Organization (id, timekeeper, Alt1Timekeeper, Alt2Timekeeper) VALUES
(1, 1, 23,45),
(2,33,1, 66),
(3, 67, 55, 1),
(4, 57, 77, 88),
(5, 1, 62, 74);
-- DDL and sample data population, end
DECLARE @employeeID INT = 3456;
DECLARE @id INT = (SELECT id FROM @employee WHERE employeeID = @employeeID);
;WITH rs AS
(
SELECT *, (
SELECT * FROM @Organization AS c
WHERE c.id = p.id
FOR XML PATH('r'), TYPE, ROOT('root')).value('some $r in /root/r/*[local-name()!=("id")]/text()
satisfies $r = sql:variable("@id")', 'BIT') AS Result
FROM @Organization AS p
)
SELECT * FROM rs
WHERE Result = 1;