Solved

oracle

Posted on 2004-09-15
9
205 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 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

11 Experts available now in Live!

Get 1:1 Help Now