I have a very large sql statement where I join five tables
and it has quite a few inner and left joins and it errors out and says select key word not found where expected, or missing expression, if anyone can give advice or help, or a solution it would be greatly appreciated.
Thanks
Danni
Here is the sql statement:
select a.abb TERRITORY, ahc AUTHORIZED_HC, bhc BUDGETED_HC,
b.total ONBOARD, c.total OPEN_REQS,
d.total THIRTY, e.total SIXTY,
f.total NINETY
from
(((
(dbo_ora a inner join
(select terr, count(ssn) total
from
dbo_detail inner join dbo_deptx on dbo_detail.dept=dbo_deptx.dept
where (dbo_detail.odate > to_date('"&date-30&"','mm/dd/yy') or dbo_detail.odate is null) and (dbo_detail.idate <=to_date('"&date&"','mm/dd/yy') or dbo_detail.idate is null)
openreqsum = openreqsum +" and ptft='F' and (reg='SE'or terr ='SE' or dist='SE')
group by terr)b on a.abb=b.terr)
left join dbo_orc c on a.abb=c.terr )
left join (select terr, count(id) total from dbo_openreq, dbo_deptx where dbo_openreq.dept=dbo_deptx.dept and dbo_openreq.opendate < to_date('"&date-30&"','mm/dd/yy') and dbo_openreq.opendate >= to_date('"&date-60&"','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) d on a.abb=d.terr)
left join (select terr, count(id) total from dbo_openreq, dbo_deptx where dbo_openreq.dept=dbo_deptx.dept and dbo_openreq.opendate < to_date('"&date-60&"','mm/dd/yy') and dbo_openreq.opendate >= to_date('"&date-90&"','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) e on a.abb=e.terr)"
left join (select terr, count(id) total from dbo_openreq, dbo_deptx where dbo_openreq.dept=dbo_deptx.dept and dbo_openreq.opendate < to_date('"&date-90&"','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) f on a.abb=f.terr
order by a.abb;
and it has quite a few inner and left joins and it errors out and says select key word not found where expected, or missing expression, if anyone can give advice or help, or a solution it would be greatly appreciated.
Thanks
Danni
Here is the sql statement:
select a.abb TERRITORY, ahc AUTHORIZED_HC, bhc BUDGETED_HC,
b.total ONBOARD, c.total OPEN_REQS,
d.total THIRTY, e.total SIXTY,
f.total NINETY
from
(((
(dbo_ora a inner join
(select terr, count(ssn) total
from
dbo_detail inner join dbo_deptx on dbo_detail.dept=dbo_deptx.dept
where (dbo_detail.odate > to_date('"&date-30&"','mm/dd/yy') or dbo_detail.odate is null) and (dbo_detail.idate <=to_date('"&date&"','mm/dd/yy') or dbo_detail.idate is null)
openreqsum = openreqsum +" and ptft='F' and (reg='SE'or terr ='SE' or dist='SE')
group by terr)b on a.abb=b.terr)
left join dbo_orc c on a.abb=c.terr )
left join (select terr, count(id) total from dbo_openreq, dbo_deptx where dbo_openreq.dept=dbo_deptx.dept and dbo_openreq.opendate < to_date('"&date-30&"','mm/dd/yy') and dbo_openreq.opendate >= to_date('"&date-60&"','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) d on a.abb=d.terr)
left join (select terr, count(id) total from dbo_openreq, dbo_deptx where dbo_openreq.dept=dbo_deptx.dept and dbo_openreq.opendate < to_date('"&date-60&"','mm/dd/yy') and dbo_openreq.opendate >= to_date('"&date-90&"','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) e on a.abb=e.terr)"
left join (select terr, count(id) total from dbo_openreq, dbo_deptx where dbo_openreq.dept=dbo_deptx.dept and dbo_openreq.opendate < to_date('"&date-90&"','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) f on a.abb=f.terr
order by a.abb;