Error with inner select statement [message #406181] |
Tue, 02 June 2009 13:12 |
deahayes3
Messages: 203 Registered: May 2006
|
Senior Member |
|
|
Hello all,
The script below works fine in sql, but when I put it in a procedure in forms I get errors around the Max select statement. Any thoughts on why I am receiving an error.
SELECT Count(DISTINCT (o.rowid))
INTO v_jan --comment out in sql
FROM incident_info o,
human_resource h
WHERE o.person_id = h.person_id
AND o.location_id = 'US'
AND (o.first_aid_only_doctor = 'Y'
OR o.first_aid = 'Y')
AND o.incident_date BETWEEN To_date('01-JAN'
||:dummy.p_year,'DD-MON-YYYY') AND Last_day(To_date('01-JAN'
||:dummy.p_year,'DD-MON-YYYY'))
AND ((Round(Months_between(To_date('01-JAN'
||:dummy.p_year,'DD-MON-YYYY'),(SELECT Max(h1.effective_start_date)
FROM human_resource h1
WHERE h1.person_id = o.person_id
AND h1.effective_start_date <= o.incident_date))) > 0))
AND ((Round(Months_between(To_date('01-JAN'
||:dummy.p_year,'DD-MON-YYYY'),(SELECT Max(h2.effective_start_date)
FROM human_resource h2
WHERE h2.person_id = o.person_id
AND h2.effective_start_date <= o.incident_date))) <= 3));
[Updated on: Tue, 02 June 2009 13:42] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Error with inner select statement [message #407703 is a reply to message #406181] |
Thu, 11 June 2009 03:03 |
nagu_bhat
Messages: 10 Registered: May 2009
|
Junior Member |
|
|
hi
try this out
select count(distinct (o.rowid))
into v_jan --comment out in sql
from incident_info o, human_resource h,
(select s.person_id sperson_id, max(t.effective_start_date) max_eff_date
from incident_info s, human_resource t
where s.person_id = t.person_id
and t.effective_start_date <= s.incident_date)
where o.person_id = h.person_id
and o.location_id = 'US'
and (o.first_aid_only_doctor = 'Y' or o.first_aid = 'Y')
and o.incident_date between trunc(to_date(:dummy.p_year.'YEAR')) and last_day(trunc(to_date(:dummy.p_year.'YEAR')))
and (round(months_between(trunc(to_date(:dummy.p_year.'YEAR')), max(eff_date)) between 1 and 3
and sperson_id (+) = o.person_id
Regards
Nagaraj
|
|
|