Link to home
Start Free TrialLog in
Avatar of Andrew
AndrewFlag for United States of America

asked on

SQL JOIN help?

Hello,

I am trying to figure out how to query 2 tables to get desired results.  The problem I am having is that the same LabName(description) is being returned for all 4 Activity Numbers instead of the corresponding LabName for each Activity Number for each row.

Current query:
SELECT RI.Location, AC.Description AS Lab1, RI.Activity1, (RI.Cost1 * 31) AS Cost1, AC.Description AS Lab2, RI.Activity2, (RI.Cost2 * 31) AS Cost2,
AC.Description AS Lab3, RI.Activity3, (RI.Cost3 * 31) AS Cost3, AC.Description AS Lab4, RI.Activity4, (RI.Cost4 * 31) AS Cost4,
 ((RI.Cost1 + RI.Cost2 + RI.Cost3 + RI.Cost4) * 31) AS TCost

FROM [SeedTracker].[dbo].[DBLogResInt] AS RI

JOIN [SeedTracker].[dbo].[ActiveCodes] AS AC
ON (RI.Activity1 = AC.ActivityCode)

ORDER BY Location

Open in new window

Results:  User generated image
[DBLogResInt]  User generated image
[ActivityCodes]  User generated image
ASKER CERTIFIED SOLUTION
Avatar of Walter Ritzel
Walter Ritzel
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andrew

ASKER

Hmmm, that didn't seem to work.
User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andrew

ASKER

That did it!  Thank you !