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(+)
--------------------
LVL 6
anumosesAsked:
Who is Participating?
 
venkotchConnect With a Mentor Commented:
donor exists where?
By doing "ds.donor IN (set)" you are pre-determining that donor should be in the temp table.
If you simply do not check the temp table it will retirn all donors for that question.
If you want to return all and tell if they exist in the temp table - then you can outer join the temp or if it is really small - better add a select statement as check.


-- outer join
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

-- select
-- outer join
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 0 = (SELECT count(*)
                     FROM temp_mobile_donors
                    WHERE temp.donor_id = ds.donor_id)
         THEN 'donor not in temp'
         ELSE 'donor in temp'
       END is_donor_in_temp
  FROM ds_malaria_travel_history ds
 WHERE ds.question_id = '1008'
 ORDER BY ds.date_left_area, ds.country_of_travel

Open in new window

0
 
venkotchCommented:
Please state clearly the problem to solve.
0
 
anumosesAuthor Commented:
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.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
anumosesAuthor Commented:
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
0
 
venkotchCommented:
So ... it means your external table is the malaria one. You should have started with this ...
Do the oposite - outer join the malaria table.
0
 
anumosesAuthor Commented:
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

0
 
anumosesAuthor Commented:
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.
0
 
venkotchCommented:
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.
0
 
anumosesAuthor Commented:
can u tell me how to use ANSI one with the "OUTER JOIN" keyword?
0
 
anumosesAuthor Commented:
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.
0
 
anumosesAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.