Solved

oracle

Posted on 2004-09-15
9
214 Views
Last Modified: 2010-05-02
I have created a query for data extraction ; I save it in the excel format and email it to user.

Sql:

select distinct mkt.last ||', '|| mkt.first mktname,
     phys.id ||'-'|| phys.last ||', '|| phys.first physname,
     phys.zip1 ||', '|| phys.state zipst, phon.phonea ||'-'|| phoneb ||'-'|| phon.phonec physphone,
     invt.manufacturer_id ||'-'|| man.name mfg,
     count(distinct ship.to_id) pats,   sum(shipi.quantity) qty

from shipments ship,
     patient_therapies pthx,
     patients_table pt,
     marketing mkt,
     shipment_items shipi,
     prescriptions_table presc,
     inventory invt,
     manufacturers man,
     physicians phys,
     phones phon

where ship.completed_date between '01-JAN-2004' AND '31-JAN-2004'
and ship.to_type = 'P'
and ship.to_id = pthx.patient_id
and ship.to_id = pt.id
and pt.marketing_id = mkt.id
and pthx.stop_date is null
and pthx.therapy_type in (select therapy_type from therapy_types
                          where therapy_class in 'HARMONE')
and ship.id = shipi.shipment_id
and shipi.inventory_id = invt.id
and invt.tdrug_abbrev is not null
and invt.manufacturer_id = man.id
and (shipi.rx_prescription_id = presc.prescription_id
    and shipi.rx_svcbr_id = presc.svcbr_id
    and shipi.rx_refill_no = presc.refill_no
    and ship.to_id = presc.patient_id)
and presc.physician_id = phys.id
and (phys.id = phon.name_id(+)
    and phon.name_type = 'D'
    and phon.phone_seq = 1)
      and phys.id = 230323

group by mkt.last ||', '|| mkt.first,
     phys.id ||'-'|| phys.last ||', '|| phys.first,
     phys.zip1 ||', '|| phys.state, phon.phonea ||'-'|| phoneb ||'-'|| phon.phonec,
     invt.manufacturer_id ||'-'|| man.name


Sample data:

MKTNAME      PHYSNAME      MFG-id and name        PATS              QTY
SCOTT, LELA      323-MATHEW      25-ABC                    1                    7
SCOTT, LELA      323-MATHEW      34-EFH                   2                    17
SCOTT, LELA      323-MATHEW      67-XYZ                   1                    14

So one row is getting repeated thrice because there are 3 entries for mfg-id and name. But I want the following to be displayed in the foll. Format. The mfg id and its corresponding name may vary every time I run the sql.  i MEAN THE mfg id and name field can be abc, efg, xyz this week and next week it could be all of the above 3 and it could be some other ones like hjk, nmk,
Or it could not have any of the abc, efg, xyz and could be only hjk, nmkCan u please tell me how to get the data out in the foll. Format??.. Please paste the code for doing it in plain sql. and also in plsql; plain sql code more important. Can this be THANKS EXPERTS!!!

MKTNAME      PHYSNAME      25-ABC      34-EFH      67-XYZ
SCOTT, LELA      323-MATHEW      7      17      14



0
Comment
Question by:Sara_j_11
[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
  • 3
  • 3
9 Comments
 

Author Comment

by:Sara_j_11
ID: 12069803
i MEAN THE mafg id and name field can be abc, efg, xyz this week and next week it could be all of the above 3 and it could be some other ones like hjk, nmk,
Or it could not have any of the abc, efg, xyz and could be only hjk, nmk
0
 
LVL 4

Expert Comment

by:Prestaul
ID: 12077208
How are you executing the query and creating the file?  VB and ADO?  If so then the easiest solution is to forget about modifying the complicated SQL, take the results as they are now, and format the results the way that you want them as you insert into the Excel file.

Oracle does not make pivoting tables easy.  If you are determined to do this with SQL then look at http://asktom.oracle.com and search for pivot.
0
 

Author Comment

by:Sara_j_11
ID: 12077913
I am using the toad editor to execute the sql and save it in the excel format. Any comments on doing it in sql would be greatly apprecited
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 4

Accepted Solution

by:
Prestaul earned 500 total points
ID: 12078204
0
 

Author Comment

by:Sara_j_11
ID: 12088729
I still dont know how to handle my case since mine is fully dynamic and the examples are for known columns..
0
 
LVL 4

Expert Comment

by:Prestaul
ID: 12089106
Sorry.  I think that you should process the data from your original query before writing the Excel file.  Good luck.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 824
Adding to a VBA? 6 85
How does CurrentUser work? 10 42
Zip Folders Using Chilkat Routines 1 77
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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