Query rows to column

dear Friends,
i need query row to column
example
1 a data1 data2 data3
2 b data1 data2 data3
output format
1 2 a
data1 data2 data3

Please consider the following when you post a question.
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
      select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
      union all
      select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
  from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id   sum_qty   count_inv
1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
   {thread:id=501834} and {thread:id=863295}.
   Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
   So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Dynamic query, row to column

    Hi.
    Is any way to select one row as column for any table exists?
    I mean some script which have table name and condition as input parameters, and prints column_name || column value;
    I have tried to do it, but have some problems.
    e.g. have table
    create table my_table (column1 number, column2 number, column3 number);
    insert into my_table values (1,2,3);It should be something like:
    declare
    lv_table_name varchar2(40):='MY_TABLE'; /*these are input paremeters*/
    lv_condition varchar2(300):='column1=1;/*these are input paremeters*/
    begin
    /*body*/
    end;and output should be like (may use dbms_output)
    column1    1
    column2    2
    column3    3    Script should work for any table.
    Does anybody solves task similar to this?

    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
    Search for procedure print_table on that page.

  • Transposing of queried rows into columns

    Hi, i have a query that produces an output of several rows (i.e. no. of days in a month).  How do I modify my query so that instead of getting 31 rows for january, I will have one row with 31 columns or values?  Thank you.

    Thank you very much for your response.  You definitely got what i wanted to do but honestly, I'm having a hard time applying this to my query since I am not very familiar with the WITH AS, CONNECT BY LEVEL and the PRIOR commands, coupled with the fact that I have to produce my output ASAP.  I have this query:
    SELECT A.PLTCODE, A.PLTACTLGEN, A.INPTDATE                    
        FROM PMC_ACTLGEN A                                       
       WHERE     A.INPTDATE >
                    TO_DATE ('10/31/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
             AND A.INPTDATE <
                    TO_DATE ('01/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
    ORDER BY                                                           --
            A.PLTCODE, A.INPTDATE
    which produce an output that looks like this:
    PLTCODE
    PLTACTLGEN
    INPTDATE
    AMB
    0
    11/1/2013
    AMB
    204
    11/2/2013
    AMB
    107
    11/3/2013
    AMB
    968
    11/4/2013
    AMB
    1379
    11/5/2013
    AMB
    1493
    11/6/2013
    AMB
    1457
    11/7/2013
    AMB
    1099
    11/8/2013
    AMB
    1893
    11/9/2013
    AMB
    2517
    11/10/2013
    AMB
    2521
    11/11/2013
    AMB
    2448
    11/12/2013
    AMB
    701
    11/13/2013
    AMB
    1785
    11/14/2013
    AMB
    2002
    11/15/2013
    AMB
    1601
    11/16/2013
    AMB
    1225
    11/17/2013
    AMB
    1572
    11/18/2013
    AMB
    1579
    11/19/2013
    AMB
    1576
    11/20/2013
    AMB
    1722
    11/21/2013
    AMB
    1610
    11/22/2013
    AMB
    175
    11/23/2013
    AMB
    813
    11/24/2013
    AMB
    1674
    11/25/2013
    AMB
    2198
    11/26/2013
    AMB
    1841
    11/27/2013
    AMB
    1970
    11/28/2013
    AMB
    1918
    11/29/2013
    AMB
    721
    11/30/2013
    How do I exactly modify this query to produce an output such that the INPTDATE is arranged as columns e.g.
    INPTDATE    1      2       3        4          5          6          7      .     .     .       30
    AMB            0     204   107     968     1379     1493    1457     .     .     .     721
    PLEASE HELP!  Thanks a lot!

  • Oracle 10g query rows to column transpose

    In oracle 10g I have table called LoginUser
    Select * from LoginUser where Day = '01-Dec-2012'
    will give me the below result
    Day, Name, Country
    1-Dec-12 , John, UK
    1-Dec12 , Cate, US
    1-Dec-12 , Prakash, India
    1-Dec-12 ,Juli, Pak
    But I want result as below
    Day, Name1, Country1, Name2, Country2, Name3, Country3, Name4, Country4
    1-Dec-12, John, UK, Cate, US, Prakash, India, Juli, Pak
    Please help
    Edited by: 975340 on Dec 6, 2012 1:48 AM
    Edited by: 975340 on Dec 6, 2012 1:50 AM

    Refer to below thread
    Re: Multiple rows into a single line in 'Single Column Table'

  • How to accessing current row report column value in Lov Query?

    Hi,
    which access methods (eg. bind variables, substitutions, ...) for getting the current row report column value can be used in the "Lov Query" property of a report column?
    As what I know of and what I have read on the forum there are no bind variables for the report columns. For the "Link Text" property it seems that the column values exist as substitution strings (#COLUMN_NAME#). But they don't work in the Lov Query. => And would be good because of a hard parse each time the Lov query is executed.
    The following post (Re: Simulating a correlated sub query in lov
    is showing a solution to use package variables for temporary storage of the referenced value, but the only problem with that solution is that if a new record is added with the "Add rows to tabular form" process the package variable still contains the value from the last queried row! Is there a way (variable, APEX package, ...) to determine if the lov query is executed for a new record so that the package can return null?
    I know that I could write the package in a way that the value is immediately cleared when lov_pkg.keyval is called (one time read), but then I would have to create several variables if I'm accessing the value multiple times in the query or in another query => I think an one time read solution would be very obscurely.
    Thanks for your help
    Patrick
    http://inside-apex.blogspot.com

    Hi Patrick,
    I agree that it's a waste to continually use Ajax to go back to the server to get the contents of a dynamic select list.
    There are no bind variables for any row item - but what you do have, as per my previous post, is the value of the data entered by the user in the first row. You can pass this into your application process (using get.add("VARIABLENAME", value)), which can use it to retrieve the correct LOV in your Ajax code - this will give you a "bind variable" that your process can use.
    What you could do, however, is generate hidden select lists on your page - one for each possible LOV list and replace the contents of the new row's select list with the contents of the appropriate hidden select list. This is easy to do with javascript (using innerHTML functions). Obviously, though, the usefulness of this depends on the number and size of the select lists.
    Even if you don't generate them to start with, you can keep a copy of any select lists returned by Ajax in the DOM for use on new rows. So, if you have retrieved a select list, you will have a copy of it in DOM which you can then copy into the new row. If you don't have the list in DOM, use Ajax to get it, store a copy of it and copy it into the new row.
    Which method you use will depend on the number/size of select lists needed. If they are few in number and/or size, I would suggest generating hidden lists. If they are large, use Ajax to get them once, store them and then retrieve them from the DOM when needed.
    There is another thread here where Arie recommends going to the server every time to make sure you get the most up-to-date data for the lists. If you want to follow this advice, for this reason, use get.add("VARIABLENAME", value) to pass the value to your process. If this is not an issue, you can use one of the other methods I outlined above.
    Regards
    Andy

  • Cursor in select query in row to column format

    Hi
    I have the query like below
    SELECT d.department_id,
                 CURSOR(SELECT e.first_name,
                         e.last_name
                  FROM   employees e
                  WHERE  e.department_id = d.department_id
           ) emps
    FROM   depatments dI want the result set in a format of Row To columns like
    10                             20
    <cursor result>   <cursor result>pls give ur suggestions how to achieve this in a efficient way?I tried the method of "max(decode(.." but dont think so its possible with this

    vishnu prakash wrote:
    Hi
    I have the query like below
    SELECT d.department_id,
    CURSOR(SELECT e.first_name,
    e.last_name
    FROM   employees e
    WHERE  e.department_id = d.department_id
    ) emps
    FROM   depatments dI want the result set in a format of Row To columns like
    10                             20
    <cursor result>   <cursor result>pls give ur suggestions how to achieve this in a efficient way?I tried the method of "max(decode(.." but dont think so its possible with thisNumber of column of a select query is static. Must be known at the parsing time itself. But in your case i dont think the number of columns will be limited to 2 (10 and 20) there could be many more.
    You can search this forum to see how to PIVOT your data. There are lot of example. You can also try dynamic pivot. Its all in here, just search.

  • How to increase the row and Column length of Bex query in EP Portal 7.3

    Dear All,
    Please let me know the process  to Increase the Rows and Columns  Size of Bex Query in Enterprise Portal  of SAP  7.3 .
    Please  let settings to increase rows up 10000 and column 100 in one page.
    Thanks
    Regards,
    Sai

    Dear All,
    Please find the attached screen shot.
    The report be open with 4 or 5 columns and 5 or 6 rows.
    So, please  let me know how to increase the length of the table.
    Do the needful for me to over come this issue.
    Thanks
    Regards,
    Sai.

  • Rows to column in 11g as single query

    I would like to create single row with column name
    as ISIN, CUSIP, SEDOL for each row which has desc IS, CU, SE
    as below
    SQL> select * from test;
          CODE DESCR                     VALUE
            10 IS                          100
            10 CU                          200
            10 SE                          200
            20 IS                          100
            20 CU                          200
            20 SE                          200
    The row should looks like below with column name ISIN, CUSIP, SEDOL
          CODE ISIN    CUSIP   SEDOL
            10 100     200      200
            20 100     200      200
    CREATE TABLE TEST
      CODE   NUMBER(10),
      DESCR  VARCHAR2(20 BYTE),
      VALUE  NUMBER(10)
    SET DEFINE OFF;
    Insert into TEST
       (CODE, DESCR, VALUE)
    Values
       (10, 'IS', 100);
    Insert into TEST
       (CODE, DESCR, VALUE)
    Values
       (10, 'CU', 200);
    Insert into TEST
       (CODE, DESCR, VALUE)
    Values
       (10, 'SE', 200);
    Insert into TEST
       (CODE, DESCR, VALUE)
    Values
       (20, 'IS', 100);
    Insert into TEST
       (CODE, DESCR, VALUE)
    Values
       (20, 'CU', 200);
    Insert into TEST
       (CODE, DESCR, VALUE)
    Values
       (20, 'SE', 200);
    COMMIT;

    Frank, the query i posted is an eg.
    in real i have 200k records in the table.
    SQL> explain plan for select * from master_base a, (SELECT  * FROM    id_xref
      2  PIVOT    (  max (SECURITY_XREF_NBR)
      3      FOR    SECURITY_XREF_CD
      4      IN    (    'IS'    AS isin
      5          ,    'CU'    AS cusip
      6          ,    'SD'    AS sedol
      7          )
      8      )
      9  ) b
    10  where a.security_nbr = b.security_nbr(+)
    11  ;
    Explained.
    Elapsed: 00:00:00.23
    SQL> set lines 200
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2437398092
    | Id  | Operation             | Name                    | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |                         |   238K|    57M|       |  7495   (2)| 00:01:30 |
    |*  1 |  HASH JOIN OUTER      |                         |   238K|    57M|  8024K|  7495   (2)| 00:01:30 |
    |   2 |   TABLE ACCESS FULL   |          MASTER_BASE | 61776 |  7299K|       |   825   (3)| 00:00:10 |
    |   3 |   VIEW                |                         |   238K|    29M|       |  4647   (2)| 00:00:56 |
    |   4 |    HASH GROUP BY PIVOT|                         |   238K|    15M|    21M|  4647   (2)| 00:00:56 |
    |   5 |     TABLE ACCESS FULL |     ID_XREF     |   238K|    15M|       |   706   (4)| 00:00:09 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - access("A"."sECURITY_NBR"="B"."SECURITY_NBR"(+))
    17 rows selected.Edited by: user520824 on Jul 22, 2010 8:28 AM
    Edited by: user520824 on Jul 22, 2010 8:31 AM

  • Converting rows to columns using dynamic query.

    I am trying to use the below code that I founnd on the web to conver rows to columns. the reason that I want to use dynamic query is that the number of rows are not know and changes.
    declare
        lv_sql varchar2(32767) := null ;
    begin
        lv_sql := 'SELECT Iplineno ';
        for lv_rec in (SELECT distinct vendor from bidtabs  where letting = '10021200' and call ='021')
        loop
            lv_sql :=   lv_sql
                        || CHR(10)
                        || ', MAX( DECODE( vendor, '
                        || chr(39)
                        || lv_rec.vendor
                        || CHR(39)
                        || ', bidprice, NULL ) ) as "'
                        || lv_rec.vendor
                        || '" ' ;
        end loop;
        lv_sql :=   lv_sql
                    || CHR(10)
                    || 'FROM bidtabs  where letting =  ''10021200''  and call =  ''021''  and lineflag = ''L''  '
                    || CHR(10)
                    || 'GROUP BY iplineno ;' ;
    here is the result
    BIDPRICE     CALL     IPLINENO     LETTING     VENDOR
    9,585     021     0010     10021200     C0104        
    1,000     021     0020     10021200     C0104        
    1,000     021     0030     10021200     C0104        
    17     021     0040     10021200     C0104        
    5     021     0050     10021200     C0104        
    11,420     021     0010     10021200     K0054        
    1,100     021     0020     10021200     K0054        
    1,100     021     0030     10021200     K0054        
    5     021     0040     10021200     K0054        
    3     021     0050     10021200     K0054        
    8,010     021     0010     10021200     V070         
    900     021     0020     10021200     V070         
    1,320     021     0030     10021200     V070         
    11     021     0040     10021200     V070         
    3     021     0050     10021200     V070         
    and here is the desired output
    CALL     IPLINENO     LETTING      C0104              K0054              V070         
    021     0010     10021200      9,585                     11,420                                   8,010
    021     0020     10021200      1,000       1,100     900
    021     0030     10021200      1,000     1,100     1,320
    021     0040     10021200       17     5     11
    021     0050     10021200      5     3     3

    Here is the error message I am getting:
    RA-06550: line 22, column 43:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
    <an identifier> <a double-quoted delimited-identifier>
    <a bind variable> << close current delete fetch lock insert
    open rollback savepoint set sql execute commit forall merge
    pipe

  • How to Increase the Rows and Columns Size of Bex Query in Enterprise Portal  of SAP  7.3

    Dear All,
    Please let me know the process how to Increase the Rows and Columns  Size of Bex Query in Enterprise Portal  of SAP  7.3 .
    Currently I am getting Only  4 columns and 10 rows in One Page .And I am getting 1,2 etc tabs for both row and column. So i want to increase the column length more than 100  and row length more than 10000.
    Please suggest me a suitable solution to over come this issue.
    Please find the Below screen shot.
    Thanks
    Regards,
    Sai

    Dear All,
    Please find the attached screen shot.
    The report be open with 4 or 5 columns and 5 or 6 rows.
    So, please  let me know how to increase the length of the table.
    Do the needful for me to over come this issue.
    Thanks
    Regards,
    Sai.

  • Rows to columns/Transpose the records Query and Display output

    hi ,
    can anyone help me query this and transpose it to this format?
    i am still a beginner in sql.
    thanks for help!
    Rows to columns/Transpose the records Query and Display output
    id     startdate     endate                    
    1111     1/2/2001     11/3/2001                    
    1111     2/5/2002     4/3/2002                    
    1111     2/6/2000     2/5/2001                    
    3333     5/2/2003     11/3/2003                    
    3333     6/2/2003     12/3/2003                    
    3333     2/6/2005     2/5/2005                    
    desired output     
    id     startdate1     endate1     startdate2     endate2     startdate3     endate3
    1111     1/2/2001     11/3/2001     2/5/2002     4/3/2002     2/6/2000     2/5/2001
    3333     5/2/2003     11/3/2003     6/2/2003     12/3/2003     2/6/2005     2/5/2005

    Have you only 3 dates for each id ?
    So, try :
    SQL> l
      1  with tbl as
      2  (select 1111 as id, to_date('01/02/2001','DD/MM/YYYY') startdate, to_date('11/03/2001','DD/MM/YYYY') enddate from dual union all
      3  select 1111 as id, to_date('02/05/2002','DD/MM/YYYY') startdate, to_date('04/03/2002','DD/MM/YYYY') enddate from dual union all
      4  select 1111 as id, to_date('02/06/2000','DD/MM/YYYY') startdate, to_date('02/05/2001','DD/MM/YYYY') enddate from dual union all
      5  select 3333 as id, to_date('05/02/2003','DD/MM/YYYY') startdate, to_date('11/03/2003','DD/MM/YYYY') enddate from dual union all
      6  select 3333 as id, to_date('06/02/2003','DD/MM/YYYY') startdate, to_date('12/03/2003','DD/MM/YYYY') enddate from dual union all
      7  select 3333 as id, to_date('02/06/2005','DD/MM/YYYY') startdate, to_date('02/05/2005','DD/MM/YYYY') enddate from dual )
      8  select id, max(decode(dr,1,startdate)) start1,
      9             max(decode(dr,1,enddate)) end1,
    10             max(decode(dr,2,startdate)) start2,
    11             max(decode(dr,2,enddate)) end2,
    12             max(decode(dr,3,startdate)) start3,
    13             max(decode(dr,3,enddate)) end3
    14  from (select id, startdate,enddate, dense_rank() over (partition by id order by startdate) dr from tbl)
    15* group by id
    SQL> /
                                                    ID START1   END1     START2   END2     START3   END3
                                                  1111 02/06/00 02/05/01 01/02/01 11/03/01 02/05/02 04/03/02
                                                  3333 05/02/03 11/03/03 06/02/03 12/03/03 02/06/05 02/05/05
    SQL> HTH,
    Nicolas.

  • Does Coloring Of Rows and Column in Query effect the Performance of Query

    Hi to all,
    Does Coloring of Rows and Column in Query via WAD or Report designer , will effect the performance of query.
    If yes, then how.
    What are the key factor should we consider while design of query in regards of Query performance.
    I shall ne thankful to you for this.
    Regards
    Pavneet Rana

    There will not be any significance perofrmance issue for Colouring the rows or columns...
    But there are various performance parameters which should be looked into while designing a query...
    Hope this PPT helps you.
    http://www.comeritinc.com/UserFiles/file/tips%20tricks%20to%20speed%20%20NW%20BI%20%202009.ppt
    rgds, Ghuru

  • Query to delete row where column value contains alphabets

    Hi,
    Could anyone please help me to get this query work.
    Query to delete row where column value contains alphabets.
    DELETE  FROM BIN_ITEM WHERE order_nmb LIKE '%[A-Z]%' || LIKE '%[a-z]%'
    Thanks and Regards,
    Deekay.

    RaminHashimzadeh wrote:
    SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0
    Ramin Hashimzade
    But that won't reject strings like 'gfgG%dgh' which aren't pure alphabetic.
    Try:
    with test_data as (
    select 'ghTYJYEhdfe' str from dual
    union
    select 'dfF5ssd' from dual
    union
    select 'rgth*dgheh' from dual
    union
    select 'ggf{' from dual
    union
    select 'rwhrhrh' from dual
    select  *
    from test_data
    where regexp_instr(str,'[^[:alpha:]]')=0;

  • How to color Rows and Columns of BI Query

    Hi to all,
    I have created BI query in query designer, with 2 structures for rows and Columns.
    Now I need that certain rows can be colored orange and certain columns as green color.
    I knew that it can be done in Query designer, but slice and dice reporting can not be done, which I required in my report.
    Is there any way I can do in WAD.
    or any other way to do that.
    i shall be thankfull to you for this.
    Regards
    Pavneet Rana

    Hi Rana,
    You can do the coloring of KF values using the report designer tool.
    Check the below links
    http://help.sap.com/SAPhelp_nw70/helpdata/en/dd/cea14119eb9f09e10000000a155106/frameset.htm
    [Creating Formatted reports using BEx Report Designer|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00ae5173-6112-2d10-d78f-e7779d269f25?QuickLink=index&overridelayout=true]
    Regards
    KP

  • How to Convert Rows to Column in Query

    Dear All,
    I'm having problems in converting the data from rows into columns. Eg:
    - item A sold on 01/01/07 = 5 kg
    - item A sold on 10/01/07 = 5 kg
    total item A sold in "JAN" = 10kg
    - item A sold on 01/03/07 = 20 kg
    total item A sold in "Mar" = 20kg
    I did a query and it appear as below (in which I need the period as column)
    Item Qty Period
    A 10 2007-01
    A 20 2007-03
    The output I need is :
    Item Jan Feb Mar
    A 10 - 20
    I've refer to the query posted in "Item History Query", even though I can get the column from Jan - Dec, but the total quantity for each month is not accurate. Please advise, and thanks for your time.
    Cheers,
    Serene

    Hello Serene,
    The Quantities will not be correct because you are using a Period Code in the Selection Criteria but it is not checked in the Select Statement. 
    But rewriting the code would cause duplicate entries for each item per months because of how the Group by clause works.
    CHECK THIS
    SELECT T1.ItemCode, T1.Dscription,
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 1 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JAN',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 2 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'FEB',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 3 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'MAR',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 4 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'APR',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 5 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'MAY',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 6 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JUN',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 7 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JUL',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 8 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'AUG',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 9 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'SEP',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 10 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'OCT',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 11 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'NOV',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 12 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'DEC',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'TOTAL'
    FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OFPR T2 ON T0.FinncPriod = T2.AbsEntry
    WHERE T0.CardName ='[%A]' AND T2.Code >='[%1]' AND T2.Code <='[%2]'
    GROUP BY T1.ItemCode, T1.Dscription, T2.F_RefDate, T2.T_RefDate
    The Only way out of this is to declare Variable and Assign the F_RefDate and T_RefDate and then use the variables in the Select Statements.
    Suda

Maybe you are looking for