Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I join these tables??

Status
Not open for further replies.

JJman

Technical User
May 8, 2003
89
IN

I have 2 tables to join where year and mth are keys ...

In both tables year is a 4 digit numeric. In one table mth is a 2 digit numeric, in the other it is a 2 character numeric (i.e. '07'). I have to maintain these formats, but how do I join on the mth fields ... ideas ??? My SQL is below, but it's not giving me what I want. Thanks!

SELECT tblitsupplieddata.countrycode,
tblitsupplieddata.mth,
b.mth,tblitsupplieddata.totalbiennialregistered,
b.unusablecountfrom tblitsupplieddata inner join
(SELECT LEFT(child_key,2) as countrycode,
FORMAT(date_received,'mm') as mth,
COUNT(Primary_Unusable_id) as unusablecount
FROM tblUnusables
WHERE ((FORMAT(date_received,'YYYY') = 2003) AND (FORMAT(date_received,'mm') >= 7)OR(FORMAT(date_received,'YYYY') = 2004) AND (FORMAT(date_received,'mm')<= 6))AND Throw_Out = No AND Unusable_type = 'NCH'GROUP BY LEFT child_key,2),FORMAT(date_received,'mm')) as b on (tblitsupplieddata.countrycode = b.countrycode and tblitsupplieddata.mth = b.mth )
WHERE ((tblitsupplieddata.year = 2003 AND tblitsupplieddata.mth >= 7)OR(tblitsupplieddata.year = 2004 AND tblitsupplieddata.mth <= 6))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top