Solved

Oracle Report Question

Posted on 2011-03-01
12
904 Views
Last Modified: 2012-05-11
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(+)
--------------------
0
Comment
Question by:anumoses
  • 7
  • 5
12 Comments
 
LVL 6

Expert Comment

by:venkotch
ID: 35011544
Please state clearly the problem to solve.
0
 
LVL 6

Author Comment

by:anumoses
ID: 35011564
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
 
LVL 6

Accepted Solution

by:
venkotch earned 250 total points
ID: 35011743
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
 
LVL 6

Author Comment

by:anumoses
ID: 35011862
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
 
LVL 6

Expert Comment

by:venkotch
ID: 35011880
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
 
LVL 6

Author Comment

by:anumoses
ID: 35011927
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Author Comment

by:anumoses
ID: 35016474
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
 
LVL 6

Expert Comment

by:venkotch
ID: 35016735
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
 
LVL 6

Author Comment

by:anumoses
ID: 35016760
can u tell me how to use ANSI one with the "OUTER JOIN" keyword?
0
 
LVL 6

Expert Comment

by:venkotch
ID: 35017256
0
 
LVL 6

Author Comment

by:anumoses
ID: 35017412
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
 
LVL 6

Author Comment

by:anumoses
ID: 35017510
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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to recover a database from a user managed backup
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now