DECLARE @table1 TABLE ( MailServerID INT NULL , MailServer VARCHAR(100) , EmailAddress VARCHAR(100) ); INSERT INTO @table1 ( MailServerID, MailServer, EmailAddress ) VALUES ( 1, -- ID - int 'server1', -- MailServerID - int 'email@example.com' ), ( 2, -- ID - int 'server2', -- MailServerID - int 'firstname.lastname@example.org' ); DECLARE @table2 TABLE ( ID INT IDENTITY(1, 1) , MailServerID INT , EmailAddress VARCHAR(100) ); INSERT INTO @table2 ( MailServerID, EmailAddress ) VALUES ( 2, -- MailServerID - int 'test@serversubtable_100.com' ), ( 2, -- MailServerID - int 'test@serversubtable_200.com.com' ); DECLARE @MailServerID INT; SET @MailServerID = 2; DECLARE @ID INT; SET @ID = 1; --If I set @ID = 4 nothing comes back when it should return email@example.com SELECT ISNULL(t2.EmailAddress, t1.EmailAddress) EmailAddress FROM @table1 t1 LEFT JOIN @table2 t2 ON t1.MailServerID = t2.MailServerID WHERE t1.MailServerID = @MailServerID AND @ID = t2.ID;
Gain unlimited access to on-demand training courses with an Experts Exchange subscription.Get Access
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE
Connect with Certified Experts to gain insight and support on specific technology challenges including: