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!

inner joins in oracle 8i while crossing five tables 2

Status
Not open for further replies.

Danni

Programmer
Feb 28, 2001
1
US
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('&quot;&date-30&&quot;','mm/dd/yy') or dbo_detail.odate is null) and (dbo_detail.idate <=to_date('&quot;&date&&quot;','mm/dd/yy') or dbo_detail.idate is null)
openreqsum = openreqsum +&quot; 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('&quot;&date-30&&quot;','mm/dd/yy') and dbo_openreq.opendate >= to_date('&quot;&date-60&&quot;','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('&quot;&date-60&&quot;','mm/dd/yy') and dbo_openreq.opendate >= to_date('&quot;&date-90&&quot;','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) e on a.abb=e.terr)&quot;
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('&quot;&date-90&&quot;','mm/dd/yy') and dbo_openreq.datefilled is null group by terr) f on a.abb=f.terr
order by a.abb;
 
Danni,
As SQL statements get more complex, it becomes more important to have them formatted in a way that is easy to read. This makes errors more visible.
For example, using nested joins makes the query more unreadable. Put line breaks where you use parentheses.
For example, a missing or misplaced parenthesis can cause unpredictable and errors.
Malcolm
 
also, consider the use of temp tables for intermediary results. Jim

oracle, vb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top