I need to grab a column called SymNumber from two different tables. Both are going to be selected using a similar criteria. Below is what I have so far and it is not working…
DECLARE @date datetime
SELECT @date = LastChangeDate
FROM QueueUpdates
SELECT DISTINCT u.CompanyCode, u.AgentId
FROM SymNumberToAgentId u, AgentIdToTradingPartner a, TradingPartner t, AgentContEd c
WHERE u.SymNumber in
(SELECT SymNumber FROM
(SELECT a.SymeNumber, c.SymNumber
FROM AgentProductTraining a, AgentContEd c
WHERE a.LastChangeDate >= @date and c.LastChangeDate >= @date) a ) and
u.AgentId = a.AgentId and a.TradingPartnerCode = t.TradingPartnerCode and t.TradingPartnerCode = 'SE2'
GO
The part that is giving me headaches is the inner query listed below. I think that adjusting this portion will allow me to grab the SymNum column from both tables.
(SELECT SymetraNumber FROM
(SELECT a.SymetraNumber, c.SymetraNumber
FROM AgentProductTraining a, AgentContEd c
WHERE a.LastChangeDate >= @date and c.LastChangeDate >= @date) a )
UNIONorUNION ALLlook like good options here: