Some SQL help needed (1 Viewer)

grades

Registered User.
Local time
Yesterday, 20:56
Joined
Apr 19, 2012
Messages
44
Hi,
I am trying to reuse some code that was taken from an Excel external connection. I think it is useable but I am getting errors trying to run it.
The error is "Syntax error (missing operator) in 'aTable.SkillTargetID=bTable.SkillTargetID LEFT JOIN (select SkillTargetID, sum(Duration) as PartBreak from dbo_t_Agent_Event_Detail where reasonCode=10' "


Code:
select DISTINCT aTable.SkillTargetID, bTable.Washroom, cTable.PartBreak, dTable.FullBreak, eTable.CoachTrain, fTable.Comm, gTable.CallBack, hTable.Meeting, iTable.Mapping, jTable.Teaching, kTable.MgrMeeting, lTable.EOS, mTable.Admin, nTable.CtiFail from
   (select SkillTargetID from dbo_t_Agent_Event_Detail) aTable
 
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as Washroom from dbo_t_Agent_Event_Detail where ReasonCode=101 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as bTable
   on aTable.SkillTargetID=bTable.SkillTargetID
 
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as PartBreak from dbo_t_Agent_Event_Detail where ReasonCode=102 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as cTable
   on aTable.SkillTargetID=cTable.SkillTargetID
 
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as FullBreak from dbo_t_Agent_Event_Detail where ReasonCode=103 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as dTable
   on aTable.SkillTargetID=dTable.SkillTargetID
 
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as CoachTrain from dbo_t_Agent_Event_Detail where ReasonCode=104 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as eTable
   on aTable.SkillTargetID=eTable.SkillTargetID
 
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as Comm from dbo_t_Agent_Event_Detail where ReasonCode=105 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as fTable
   on aTable.SkillTargetID=fTable.SkillTargetID
 
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as CallBack from dbo_t_Agent_Event_Detail where ReasonCode=106 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as gTable
   on aTable.SkillTargetID=gTable.SkillTargetID
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as Meeting from dbo_t_Agent_Event_Detail where ReasonCode=107 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as hTable
   on aTable.SkillTargetID=hTable.SkillTargetID
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as Mapping from dbo_t_Agent_Event_Detail where ReasonCode=108 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as iTable
   on aTable.SkillTargetID=iTable.SkillTargetID
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as Teaching from dbo_t_Agent_Event_Detail where ReasonCode=109 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as jTable
   on aTable.SkillTargetID=jTable.SkillTargetID
   LEFT JOIN
   (select SkillTargetID, sum(Duration) sa MgrMeeting from dbo_t_Agent_Event_Detail where ReasonCode=110 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as kTable
   on aTable.SkillTargetID=kTable.SkillTargetID
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as EOS from dbo_t_Agent_Event_Detail where ReasonCode=111 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID)as  lTable
   on aTable.SkillTargetID=lTable.SkillTargetID
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as Admin from dbo_t_Agent_Event_Detail where ReasonCode=112 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as mTable
   on aTable.SkillTargetID=mTable.SkillTargetID
   LEFT JOIN
   (select SkillTargetID, sum(Duration) as CtiFail from dbo_t_Agent_Event_Detail where ReasonCode=50002 and DbDateTime >= forms!frmmain!dt1 and DbDateTime < forms!frmmain!dt2 group by SkillTargetID) as nTable
   on aTable.SkillTargetID=nTable.SkillTargetID

My table contains the SkillTargetID, Duration, and ReasonCodes. To be honest, i am not sure what aTable, bTable etc do, but i think it would be great to get all this data in one query if possible. If I cannot use this, is there anyway to retrieve all the data within one query? The data being who (SkillTargetID) was in what break (ReasonCode) for how long (Duration).
I apologize for the uneducated question.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 13:56
Joined
Jan 20, 2009
Messages
12,854
Access requires its joins nested in parentheses like this:

Code:
FROM
(((a LEFT JOIN b ON a.x = b.x) LEFT JOIN c ON a.x = c.x) LEFT JOIN d ON a.x = d.x)
 

grades

Registered User.
Local time
Yesterday, 20:56
Joined
Apr 19, 2012
Messages
44
works like a charm, tyvm
 

Users who are viewing this thread

Top Bottom