1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Export to Microsoft Excel by group variable

Discussion in 'SQL PL/SQL' started by epr55, Oct 17, 2013.

  1. epr55

    epr55 Guest


    I have to export the results of a query to an Excel spreadsheet. Easy enough; however it is that I have to do it for each group. What I want to do is to be able to save it in a file that has the group number.

    This is the query
    Lets say that I have the groups in the valiable RegionID: 11213, 21345 and 6537

    @export on;
    @export set filename="C:\11213\IP_claims_11213_.xls"
    select * from mytable
    where RegionID=11213;

    How I can make it that I do not have to manually change the folder name in the direction and the where statement for each RegionID?
  2. zargon

    zargon Community Moderator Forum Guru

    Likes Received:
    Trophy Points:
    Aurora, CO
    I have no idea what this export.sql script does; you should post its content so we all can understand what you are calling.

    That being said it's pretty easy to set up a script to call a query and pass in a regionid value:

    Code (SQL):

    spool c:\&&1\IP_claims_&&1._.xls
    SELECT * FROM mytable
    WHERE regionid=&&1;
    Each passed regionid value will set a new directory and filename for the data and it will also set the regionid in the where clause.