[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now



Posted on 2004-09-15
Medium Priority
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.


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

Question by:Sara_j_11
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

Author Comment

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

Expert Comment

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.

Author Comment

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

Prestaul earned 2000 total points
ID: 12078204

Author Comment

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

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

649 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