Link to home
Start Free TrialLog in
Avatar of anumoses
anumosesFlag for United States of America

asked on

Oracle Report Question

I have this another query --------

select ds.donor_id,ds.country_of_travel,
ds.date_left_area,
ds.amt_time_spent,
ds.travel_method,
ds.staff_states,
ds.comments,'Y' || '         ' || ' N' as one,
'Y' || '         ' || ' N' as two
from ds_malaria_travel_history ds
where ds.question_id = '1008'
and ds.donor_id IN
        (SELECT donor_id FROM temp_mobile_donors)
order by ds.date_left_area, ds.country_of_travel
-------------------------
This prints only if donor exists in the table. Here I have only one table. So how can I have the hist join? How can I do the methods you earlier told
SELECT dc.country_id,
       dc.description,
       dt.question_id,
       hist.years,
       hist.amt_time_spent,
       hist.donor_id,
       CASE
         WHEN (hist.donor_id IS NULL)
         THEN 'No donors found'
         ELSE hist.donor_id
       END donor_exists
  FROM ds_travel_countries dt,
       ds_countries dc,
       (SELECT ds.years,
               ds.amt_time_spent,
               ds.question_id,
               ds.country_id,
               ds.donor_id
          FROM ds_travel_history ds
         WHERE ds.donor_id IN
              (SELECT donor_id FROM temp_mobile_donors)
       ) hist
 WHERE dt.question_id = '1010'
   AND dc.country_id = dt.country_id
   AND dt.question_id = hist.question_id(+)
   AND dt.country_id = hist.country_id(+)
--------------------
Avatar of venkotch
venkotch

Please state clearly the problem to solve.
Avatar of anumoses

ASKER

select ds.donor_id,ds.country_of_travel,
ds.date_left_area,
ds.amt_time_spent,
ds.travel_method,
ds.staff_states,
ds.comments,'Y' || '         ' || ' N' as one,
'Y' || '         ' || ' N' as two
from ds_malaria_travel_history ds
where ds.question_id = '1008'
and ds.donor_id IN
        (SELECT donor_id FROM temp_mobile_donors)
order by ds.date_left_area, ds.country_of_travel
---------
Need to modify this query to print blank if donor does not exist and print data if donor exists.
ASKER CERTIFIED SOLUTION
Avatar of venkotch
venkotch

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DONOR_ID

DN00566342  -- only this donor has data in the ds_malaria_travel_history table.
DN20235147 -- No data. But need to print blank sheet with all boiler plates and header info but no data in the columns.
The query you have posted is not working. I am getting totally different donors.

three.JPG
So ... it means your external table is the malaria one. You should have started with this ...
Do the oposite - outer join the malaria table.
SELECT ds.donor_id,
       ds.country_of_travel,
       ds.date_left_area,
       ds.amt_time_spent,
       ds.travel_method,
       ds.staff_states,
       ds.comments,
       'Y' || '         ' || ' N' as one,
       'Y' || '         ' || ' N' as two,
       CASE
         WHEN temp.donor_id IS NULL
         THEN 'donor not in temp'
         ELSE 'donor in temp'
       END is_donor_in_temp
  FROM ds_malaria_travel_history ds,
       temp_mobile_donors temp
 WHERE ds.question_id = '1008'
   AND ds.donor_id(+) = temp.donor_id
 ORDER BY ds.date_left_area, ds.country_of_travel

I tried outer join on malaria table. But it still gives me one page for the existing donor. Does not give me a blank page with headers for non existing donor.
You MUST outer join all of the columns in the outer-joined table. This is a basic SQL. If it is hard for you to use Oracle syntax, then use the ANSI one with the "OUTER JOIN" keyword. And of course, the CASE statement is no longer doing what was intent to do.
can u tell me how to use ANSI one with the "OUTER JOIN" keyword?
I tried using

SELECT ds.donor_id,
       ds.country_of_travel,
       ds.date_left_area,
       ds.amt_time_spent,
       ds.travel_method,
       ds.staff_states,
       ds.comments,
       'Y' || '         ' || ' N' as one,
       'Y' || '         ' || ' N' as two
  FROM temp_mobile_donors temp
  RIGHT OUTER JOIN ds_malaria_travel_history ds ON (ds.donor_id = temp.donor_id)
 WHERE ds.question_id = '1008'
 ORDER BY ds.date_left_area, ds.country_of_travel
-------------------
This gives me every one. But earlier when I tried using

SELECT ds.donor_id,
       ds.country_of_travel,
       ds.date_left_area,
       ds.amt_time_spent,
       ds.travel_method,
       ds.staff_states,
       ds.comments,
       'Y' || '         ' || ' N' as one,
       'Y' || '         ' || ' N' as two,
       CASE
         WHEN temp.donor_id IS NULL
         THEN 'donor not in temp'
         ELSE 'donor in temp'
       END is_donor_in_temp
  FROM ds_malaria_travel_history ds,
       temp_mobile_donors temp
 WHERE ds.question_id(+) = '1008'
   AND ds.donor_id(+) = temp.donor_id
 ORDER BY ds.date_left_area, ds.country_of_travel

I got 2 lines for donor that is in the table and blank line for the donor that does not exist.But the problem is I am not able to print 2 different pages. One for each donor. I tried setting max page to 1 and also break to Yes. But it does not work.
You can see the first donor has data. Second donor has no data but only blank lines. This is what I want, but printing on different pages. i.e page break. I tried max of 1 page and also page break yes on frame. But does not work.
two.JPG