Solved

Oracle query

Posted on 2015-01-27
9
159 Views
Last Modified: 2015-02-02
I have a query

select SUM(CASE
       WHEN da.attrib_value IN ( '04', '05' ) THEN 1
       ELSE 0
       END )
FROM (blood_drives bd
   join donations_don d ON 'DRV'||to_char(bd.drive_id) = d.drive_id
   JOIN sites s on s.site_code = bd.site_code)
   left outer join donation_attributes_don da
     ON ( d.transaction_id = da.transaction_id
    AND da.attrib_value IN ( '04', '05' )
    AND da.attrib_code = 'VENI' )
  WHERE bd.drive_date between :start_date and :end_date
    AND d.unit_id IS NOT NULL
    and area_rep_no = :area_rep_no;

I need to pass this value into a variable called v_count . I tried using into v_count after SUM(CASE
       WHEN da.attrib_value IN ( '04', '05' ) THEN 1
       ELSE 0
       END ) but I am getting an error. Help appreciated. I know it might be a simple and known error that I am getting confused.
0
Comment
Question by:anumoses
  • 5
  • 3
9 Comments
 
LVL 6

Author Comment

by:anumoses
ID: 40572671
I am using this query in a report and the error I get I have attached as a screen print. error
0
 
LVL 32

Expert Comment

by:awking00
ID: 40572683
Remove the parentheses. The query thinks you are selecting from a subquery.
0
 
LVL 6

Author Comment

by:anumoses
ID: 40572692
before the blood_drives table?
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 32

Expert Comment

by:awking00
ID: 40572705
Remove the parentheses before blood_drives bd, after bd.site_code, before d.transaction_id, and after 'VENI'
0
 
LVL 6

Author Comment

by:anumoses
ID: 40572733
select SUM(CASE
       WHEN da.attrib_value IN ( '04', '05' ) THEN 1
       ELSE 0
       END ) into v_count2
FROM blood_drives bd
   join donations_don d ON 'DRV'||to_char(bd.drive_id) = d.drive_id
   JOIN sites s on s.site_code = bd.site_code
   left outer join donation_attributes_don da
     ON  d.transaction_id = da.transaction_id
    AND da.attrib_value IN ( '04', '05' )
    AND da.attrib_code = 'VENI'  
  WHERE bd.drive_date between :start_date and :end_date
    AND d.unit_id IS NOT NULL
    and area_rep_no = :area_rep_no;

still get an error

error
0
 
LVL 6

Author Comment

by:anumoses
ID: 40572771
I modified the query

select SUM(CASE
       WHEN da.attrib_value IN ( '04', '05' ) THEN 1
       ELSE 0
       END ) into v_count2
from blood_drives bd,
     donations_don d,
     sites s,
     donation_attributes_don da    
where 'DRV'||to_char(bd.drive_id) = d.drive_id
  and s.site_code = bd.site_code
  and d.transaction_id = da.transaction_id
  AND da.attrib_value IN ( '04', '05' )
   AND da.attrib_code = 'VENI'
   and bd.drive_date between :start_date and :end_date
   AND d.unit_id IS NOT NULL
   and area_rep_no = :area_rep_no;

Just need to know if this translates to the old query and that I would get the same result?
0
 
LVL 32

Accepted Solution

by:
awking00 earned 250 total points
ID: 40572947
I think you need to state d.transaction_id = da.transaction_id(+) to make it equivalent to the left join in your original query.
0
 
LVL 35

Assisted Solution

by:Mark Geerlings
Mark Geerlings earned 250 total points
ID: 40573334
I believe awking00 is correct, in terms of the syntax, but that brings up a logical question for what looks like an inconsistency in your query.   If you need to check two additional columns in that table, then it isn't an outer join any more, because those conditions cannot be true for rows that are missing.
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 40583916
thanks
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

813 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

15 Experts available now in Live!

Get 1:1 Help Now