Solved

Oracle query

Posted on 2015-01-27
9
155 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 31

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

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

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle Pivot 2 43
Oracle - Query Insert and Update multiple tables 5 56
Processing of multiple cursor 6 35
Query to identify changes between rows of two tables 8 37
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.

914 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

12 Experts available now in Live!

Get 1:1 Help Now