I have 2 tables. TableA
has columns OldLogin and NewLogin. TableB
has ID, IsManager, and CanChange.
I'm writing a stored procedure with an input parameter login
. It needs ultimately return all columns in TableB
where login = ID
but it first needs to check TableA
to see if it needs to use NewLogin.
So, can someone help me write a query that says "show me all columns in TableB
where ID = (login OR NewLogin)"?
Thanks!
EDIT: Added code:
DECLARE @login varchar(30) = 'test'
SELECT ISNULL(NewLogin, @login) AS NewLogin, TableB .IsManager, TableB.CanChange
FROM TableA
LEFT JOIN TableB ON TableB.ID = ISNULL(NewLogin, @login)
WHERE OldLogin = @login
THe above code works only if @login exists in TableA. I get no results if it doesn't exist in that table.