Solved

Oracle Report Question

Posted on 2011-03-01
12
909 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious sideā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

734 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