How to add a dummy row in the result set of a SELECT statement.

Hello Everyone -
I have requirment to add a dummy row in the result set of a SELECT statement.
For e.g. lets say there is a table Payment having following colums:
Payment_id number
status varchar2(10)
amount number
payment_date date
so here is the data :-
Payment_id Status Amount payment_date
1 Applied 100 12/07/2008
2 Reversed 200 01/ 06/2009
3 Applied 300 01/ 07/2009
Here is my SQL
Select * form payment where payment_date >= 01/01/2009
Output will be
2 Reversed 200 01/ 06/2009
3 Applied 300 01/ 07/2009
My desired output is below
2 Reversed 200 01/ 06/2009
3 Applied 300 01/ 07/2009
2 Reversed -200 01/ 06/2009 ------(Dummy Row)
Thrid row here is the dummy row which I want to add when status is "Reversed"
I would be very thankful for any kind of help in this regard ...
Thanks,
Gaurav

Cartesion joining against a dummy table is a useful method of creating a dummy row:
with my_tab as (select 1 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                select 1 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                select 1 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                select 2 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                select 2 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/05/2009', 'mm/dd/yyyy') payment_date from dual union all
                select 2 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                select 2 cust_id, 4 Payment_id, 'Reversed' Status, -400 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                select 2 cust_id, 5 Payment_id, 'Applied' Status, 500 Amount, to_date('01/07/2009', 'mm/dd/yyyy') payment_date from dual),
                --- end of mimicking your table
      dummy as (select 'Reversed' col1, 1 rn from dual union all
                select 'Reversed' col1, 2 rn from dual)
select mt.cust_id,
       mt.payment_id,
       mt.status,
       decode(dummy.rn, 2, -1*mt.amount, mt.amount) amount,
       mt.payment_date
from   my_tab mt,
       dummy
where  mt.status = dummy.col1 (+)
order by mt.cust_id, mt.payment_id, dummy.rn nulls first;
CUST_ID     PAYMENT_ID     STATUS     AMOUNT     PAYMENT_DATE
1     1     Applied     100     07/12/2008
1     2     Reversed     200     06/01/2009
1     2     Reversed     -200     06/01/2009
1     3     Applied     300     06/01/2009
2     1     Applied     100     07/12/2008
2     2     Reversed     200     05/01/2009
2     2     Reversed     -200     05/01/2009
2     3     Applied     300     06/01/2009
2     4     Reversed     -400     06/01/2009
2     4     Reversed     400     06/01/2009
2     5     Applied     500     07/01/2009Edited by: Boneist on 07-Jan-2009 23:10
NB. You may have to mess around with the ordering if that's not come back in the order you wanted. You didn't mention what the rules were for any expected ordering though, so I've made up my own *{;-)
Also, I added an identifier (cust_id) to differentiate between different sets of payments, since that's usually the case. Remove that if it's not applicable for your case.

Similar Messages

  • How to return the result set of multiple select statements as one result set?

    Hi All,
    I have multiple select statements in my stored procedure that I want to return as one result set 
    for instance 
    select id from tableA
    union 
    select name from table b 
    but union will not work because the result sets datatypes are not identical so how to go about this ?
    Thanks

    You have to CAST or CONVERT (or implicitly convert) the columns to the same datatype.  You must find a datatype that both columns can be converted to without error.  In your example I'm guessing id is an int and name is a varchar or nvarchar. 
    Since you didn't convert the datatypes, SQL will use its data precedence rules and attempt to convert name to an int.  If any row contains a row that has a value in name that cannot be converted to an int, you will get an error.  The solution is
    to force SQL to convert the int to varchar.  So you want something like
    select cast(id as varchar(12)) from tableA
    union
    select name from tableb
    If the datatypes are something other that int or varchar, you must find a compatable datatype and then convert one (or both) of the columns to that datatype.
    Tom

  • How to add A single row at the middle of the table in a Webi report

    Hi,
         I created a Webi report using Universe(Created universe using bex query).Now i have a requirement to display a row at the middle of a report. Can you please tell me ,how to add a sigle row at the middle of a Webi report.
                                                    Thanks in advance
    Regards
    Monika

    Hi Monika,
    It is not really possible to add a row (I assume you mean of unrelated data) to the middle of a table in a report. You can add a new table with a single row between two tables. For instance you could add a new one row table, or even single cells which are positioned relatively between two tables. Possibly a block on top of another. But this gets tricky.
    Can you explain in more detail what you are trying to do?
    Thanks

  • How to exclude the XML declaration from each row of the result set?

    Hi,
    I have a table with an XMLTYPE column and would like to SELECT a set of rows. How can I exclude the XML declaration from each row in the result set? My query currently looks like this, I'm executing it through Spring JDBC:
    SELECT XMLSerialize(CONTENT t1.xmltext) FROM myschema.event t1 WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e") ORDER BY t1.time DESC
    After selecting, in my application I convert each row into a String and concatenate all rows into one big string in order to parse it into a DOM model. I get a parser exception (org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed) because there are multiple XML declarations in my big string. Of course, I could manually check the String of each row whether it starts with the XML declaration, but it would be nicer if I could instruct the DB not to add it in the first place. Is there a way?
    Thanks!
    -- Daniela

    Hi,
    A couple of options I can think of :
    SELECT XMLSerialize(CONTENT
    XMLtransform(t1.xmltext,
      xmltype('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes"/> 
    <xsl:template match="/"><xsl:copy-of select="*"/></xsl:template>
    </xsl:stylesheet>')
    FROM myschema.event t1
    WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
    ORDER BY t1.time DESC
    ;or simply,
    SELECT XMLSerialize(CONTENT
      extract(t1.xmltext,'/')
    FROM myschema.event t1
    WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
    ORDER BY t1.time DESC
    ;

  • Getting specific row of the result set.

    table: employee
    empno           number(20)
    ssan           varchar2(9)
    date_time_stamp date
    My Sql gets all the empno where ssan and date_time_stamp are equal.
    However I need previous row from max(empno) where ssan & date_time_stamp are equal.
    For eg:
    empno     ssan           date_time_stamp
    100     123456789     01-FEB-2004
    101     000000000     02-FEB-2004
    102     123456789     01-FEB-2004
    103     123456789     01-FEB-2004
    105     123456789     01-FEB-2004
    I need row with empno = 103.
    My current sql fetches all rows for particular ssan where ssan and date time stamp are equal that fetches all empno for particular ssan and date time stamp. I want the max(empno) -1 (previous row of the result set).
    Here is my sql:
    select empno,ssan,date_time_stamp
    from employee e
    where date_time_stamp in (select date_time_stamp from employee where e.ssan = ssan)
    order by empno,ssan;
    The above sql will fetch
    empno     ssan           date_time_stamp
    100     123456789     01-FEB-2004
    102     123456789     01-FEB-2004
    103     123456789     01-FEB-2004 ---&gt; I need this row, previous row from max(empno) where ssan and date time
    stamp are matching.
    105     123456789     01-FEB-2004
    101     000000000     02-FEB-2004

    If I understand correctly, you want the second highest empno for each unique combination of ssan and date_time_stamp. If so, given
    SQL> SELECT * FROM employee;
         EMPNO SSAN      DATE_TIME_S
           102 123456789 01-feb-2004
           103 123456789 01-feb-2004
           105 123456789 01-feb-2004
           100 123456678 01-feb-2004
           102 123456678 01-feb-2004
           103 123456678 01-feb-2004
           101 000000000 02-feb-2004
           105 123456678 01-feb-2004
           100 123456678 02-feb-2004
           102 123456678 02-feb-2004
           103 123456678 02-feb-2004
           105 123456678 02-feb-2004
           100 123456789 01-feb-2004Then something like this should do it.
    SQL> SELECT empno,ssan,date_time_stamp
      2  FROM (SELECT empno,ssan,date_time_stamp,
      3               RANK() OVER (PARTITION BY ssan,date_time_stamp
      4                            ORDER BY empno DESC) rk
      5        FROM employee)
      6* WHERE rk = 2;
         EMPNO SSAN      DATE_TIME_S
           103 123456678 01-feb-2004
           103 123456678 02-feb-2004
           103 123456789 01-feb-2004HTH
    John

  • Getting message : The result set for this selection was empty on sm20

    Hi,
       I assigned below parameters in rz10 :
    rsau/user_selection                                 1
    rsau/max_diskspace/per_day                  1950M
    rsau/max_diskspace/per_file                 650M
    rsau/enable                                               1
       I activated security audit profile in sm19 also.But when iam going to sm20 for analysis of security audit log iam not getting report iam getting this message  :     The result set for this selection was empty.
    Gudie me for the same.
    Thanku

    Hi,
    The result set for this selection was empty.
    I think your configuration is OK except one thing...
    Check in SM19, if you have selected "Filter Active" check box in "Filter 1 and Filter 2" screen and Also "Audit Classess".
    Even though security audit is enabled in SM19, without selecting filter it will not log the events and give you the above message.
    Regards.
    Rajesh Narkhede

  • How to add entire new row at the top of table in pdf report from c# windows forms using iTextSharp

    Hi for past 3 days i was thinking and breaking my head on how to add entire new at top table created in pdf report from c# windows forms with iTextSharp.
    First: I was able to create/export sql server data in form of table in pdf report from c# windows forms. Given below is the code in c#.
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Text;
    using System.Data;
    using System.IO;
    using System.Data.SqlClient;
    using System.Windows.Forms;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    namespace DRRS_CSharp
    public partial class frmPDFTechnician : Form
    public frmPDFTechnician()
    InitializeComponent();
    private void btnExport_Click(object sender, EventArgs e)
    Document doc = new Document(PageSize.A4.Rotate());
    var writer= PdfWriter.GetInstance(doc, new FileStream("Technician22.pdf", FileMode.Create));
    doc.SetMargins(50, 50, 50, 50);
    doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
    doc.Open();
    PdfPTable table = new PdfPTable(7);
    table.TotalWidth=585f;
    table.LockedWidth = true;
    PdfPTable inner = new PdfPTable(1);
    inner.WidthPercentage = 115;
    PdfPCell celt=new PdfPCell(new Phrase(new Paragraph("Institute/Hospital:AIIMS,NEW DELHI",FontFactory.GetFont("Arial",14,iTextSharp.text.Font.BOLD,BaseColor.BLACK))));
    inner.AddCell(celt);
    Paragraph para = new Paragraph("DCS Clinical Report-Technician wise", FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
    para.Alignment = iTextSharp.text.Element.TITLE;
    iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("logo5.png");
    png.ScaleToFit(95f, 95f);
    png.Alignment = Element.ALIGN_RIGHT;
    SqlConnection conn=new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
    SqlCommand cmd = new SqlCommand("Select t.technician_id,td.Technician_first_name,td.Technician_middle_name,td.Technician_last_name,t.technician_dob,t.technician_sex,td.technician_type from Techniciandetail td,Technician t where td.technician_id=t.technician_id and td.status=1", conn);
    conn.Open();
    SqlDataReader dr;
    dr = cmd.ExecuteReader();
    table.AddCell("ID");
    table.AddCell("First Name");
    table.AddCell("Middle Name");
    table.AddCell("Last Name");
    table.AddCell("DOB" );
    table.AddCell("Gender");
    table.AddCell("Designation");
    while (dr.Read())
    table.AddCell(dr[0].ToString());
    table.AddCell(dr[1].ToString());
    table.AddCell(dr[2].ToString());
    table.AddCell(dr[3].ToString());
    table.AddCell(dr[4].ToString());
    table.AddCell(dr[5].ToString());
    table.AddCell(dr[6].ToString());
    dr.Close();
    table.SpacingBefore = 15f;
    doc.Add(para);
    doc.Add(png);
    doc.Add(inner);
    doc.Add(table);
    doc.Close();
    The code executes well with no problem and get all datas from tables into table in PDF report from c# windows forms.
    But here is my problem how can i align Title(DCS Clinical Report-Technician wise) center of pdf report with image named:logo5.png immediately coming to it's right?.
    As the problem i am facing is my title or Header(DCS Clinical Report-Technician wise) is at top of my image named:logo5.png and not coming to it's center position of my image.
    Second the problem i am facing is how to add new entire row to top of existing table in pdf report from c# windows form using iTextSharp?.
    given in below is the row and it's data . So how do i add the given below row and it's data to my top my table in pdf report from c# windows forms using itextsharp?
    as you can see how i create my columns in table in pdf report and populate it with sql server data. Given the code below:
    Document doc = new Document(PageSize.A4.Rotate());
    var writer= PdfWriter.GetInstance(doc, new FileStream("Technician22.pdf", FileMode.Create));
    doc.SetMargins(50, 50, 50, 50);
    doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
    doc.Open();
    PdfPTable table = new PdfPTable(7);
    table.TotalWidth=585f;
    table.LockedWidth = true;
    Paragraph para = new Paragraph("DCS Clinical Report-Technician wise", FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
    para.Alignment = iTextSharp.text.Element.TITLE;
    iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("logo5.png");
    png.ScaleToFit(95f, 95f);
    png.Alignment = Element.ALIGN_RIGHT;
    SqlConnection conn=new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
    SqlCommand cmd = new SqlCommand("Select t.technician_id,td.Technician_first_name,td.Technician_middle_name,td.Technician_last_name,t.technician_dob,t.technician_sex,td.technician_type from Techniciandetail td,Technician t where td.technician_id=t.technician_id and td.status=1", conn);
    conn.Open();
    SqlDataReader dr;
    dr = cmd.ExecuteReader();
    table.AddCell("ID");
    table.AddCell("First Name");
    table.AddCell("Middle Name");
    table.AddCell("Last Name");
    table.AddCell("DOB" );
    table.AddCell("Gender");
    table.AddCell("Designation");
    while (dr.Read())
    table.AddCell(dr[0].ToString());
    table.AddCell(dr[1].ToString());
    table.AddCell(dr[2].ToString());
    table.AddCell(dr[3].ToString());
    table.AddCell(dr[4].ToString());
    table.AddCell(dr[5].ToString());
    table.AddCell(dr[6].ToString());
    dr.Close();
    table.SpacingBefore = 15f;
    doc.Add(para);
    doc.Add(png);
    doc.Add(table);
    doc.Close();
    So my question is how to make my column headers in bold?
    So these are my questions.
    1. how can i align Title(DCS Clinical Report-Technician wise) center of pdf report with image named:logo5.png immediately coming to it's right?.
    2. how do i add the given below row and it's data to my top my table in pdf report from c# windows forms using itextsharp?
    3.how to make my column headers in bold?
    I know that i have to do some modifications to my code but i dont know how to do it. Can anyone help me please.
    Any help or guidance in solving this problem would be greatly appreciated.
    vishal

    Hi,
    >>1. how can i align Title(DCS Clinical Report-Technician wise) center of pdf report with image named:logo5.png immediately coming to it's right?.
    2. how do i add the given below row and it's data to my top my table in pdf report from c# windows forms using itextsharp?
    3.how to make my column headers in bold?<<
    I’m sorry for the issue that you are hitting now.
    This itextsharp is third party control, for this issue, I recommended to consult the control provider directly, I think they can give more precise troubleshooting.
    http://sourceforge.net/projects/itextsharp/
    Thanks for your understanding.
    Regards,
    Marvin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • INSERTing a blank row in the result set

    Hi friends,
    SELECT * FROM EMPLOYEES ORDER BY DEPARTMENT_ID;
    In the result of the above, I need to INSERT a blank row in the result for each DEPARTMENT_ID. i.e., the result should look like the following:
    EMP_ID - NAME - SALARY - DEPARTMENT_ID
    101 - Albert - 10,000 - 10
    102 - Benjamin - 8,000 - 10
    103 - Chitra - 10,500 - 20
    104 - David - 4,500 - 20
    105 - Elango - 6,000 - 20
    106 - Fathima - 6,000 - 30
    107 - Ganga - 9,000 - 30
    etc.
    I don't want to insert into the table. Just in display I need a blank row.
    Thanks in advance.
    Edited by: Iniyavan on Mar 8, 2010 11:37 AM

    Are you looking for this?
    satyaki>select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
    14 rows selected.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>break on deptno
    satyaki>
    satyaki>
    satyaki>select empno,
      2            ename,
      3            sal,
      4            deptno
      5     from emp
      6     order by deptno;
         EMPNO ENAME             SAL     DEPTNO
          7782 CLARK            2450         10
          7839 KING             5000
          7934 MILLER           1300
          7566 JONES            2975         20
          7902 FORD             3000
          7876 ADAMS            1100
          7369 SMITH             800
          7788 SCOTT            3000
          7521 WARD             1250         30
          7844 TURNER           1500
          7499 ALLEN            1600
         EMPNO ENAME             SAL     DEPTNO
          7900 JAMES             950         30
          7698 BLAKE            2850
          7654 MARTIN           1250
    14 rows selected.
    Elapsed: 00:00:00.04
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • How to add an extra row at the end of the Grid?

    Hi gurus,
    I am getting result from the select query which has 4 columns.
    I got the requirement to display the sum of those columns as the last row.
    How can i add the another row at the end of the iGrid ?
    Data would look like
    Sno  Col1   Col2  Col3  Col4
    1         4       6      1       6
    2         5       8      0       8
    3         6       1      2       5
    Sum     15     14    3       19
    Do i have to add transformation to the sql query? or
    Can i add row to the display tempalate by accessing the Gridobject?
    Please help.
    Thanks
    Vansi
    Edited by: vamsi P on Feb 12, 2008 8:49 PM
    Edited by: vamsi P on Feb 12, 2008 8:49 PM

    Hi Vamsi,
    There are a few options ...
    1) The one suggested by Prasanna
    2) Loop through all rows via JavaScript and use the GridObject methods to set cell values and then perform an applet.refreshGrid( false )
    3) Apply an Inline transform
    4) Use a stored procedure to return the results and the totals as one recordset.
    The stored procedure would be the fastest for runtime.
    The Iniline XSL transform would be the second fastest.  If you specify the XSL in a generic way, you may even be able to reuse it in other scenarios.  If you hardcode the fields in the XSL, it would be a matter of simple code adjustment when you encounter a similar scenario.
    Hope this helps.
    Cheers,
    Jai.

  • How to add a new row at the top of manual tabular form

    I have a manual tablular form. I'm trying to add a row at the top of the form, instead of new row of being displayed at the bottom. any ideas are appreciated.
    thanks,
    Surya

    This will depend on two things:
    1. sorting of the columns - needs to be a some kind of a descending sorting on a hidden column, enabled within the Report Attributes and not in the SQL Query
    2. Report Attributes => Layout and Pagination => Sort Nulls First
    You will need to play with those settings a bit. One thing to consider is that you should sort your report on a hidden column and you shuldn't enable the sorting on visible columns, because it will mess up your row positioning.
    See this example:
    http://apex.oracle.com/pls/otn/f?p=31517:215
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How can i display units only for the result set

    hi
    i do not want to display units (example: $ or %) for my key figure columns but i want to display units to the result.
    how can i do that

    Hi Surya,
    I don't think it is possible to have both non-unit and unit in the same kf.
    One potential workaround to do this is to create a calculated key figure/ formula that use the NODIM function for single values. Example: NODIM(0AMOUNT). Then, create a calculated key figure/formula that computes overall result on the same kf and supresses individual values but does not use NODIM....perhaps this can help you work out a solution.
    Hope this helps.
    Regards,
    Petter
    Message was edited by: M Petter

  • Inserting row in the result set

    Hi
    need to insert a row in resultset when previous row typ=c and next row typ=p then need to insert one row in between typ c and p with typ =s see the #temp_result table for result expected
    --drop table temp1
    --drop table temp1_result
    --presently data:-
    create table temp1
    (id int,
    ord int,
    typ varchar(2),
    dt date)
    insert into temp1 values (101, 1, 'c', '2001-10-01')
    insert into temp1 values (101, 2, 'p', '2001-11-11')
    insert into temp1 values (102, 1, 'c', '2002-10-01')
    insert into temp1 values (102, 2, 'p', '2002-11-01')
    insert into temp1 values (102, 3, 'p', '2002-12-01')
    insert into temp1 values (103, 1, 'c', '2003-10-01')
    insert into temp1 values (103, 2, 'p', '2003-11-01')
    insert into temp1 values (104, 1, 'c', '2004-10-01')
    insert into temp1 values (104, 2, 'c', '2004-11-01')
    insert into temp1 values (104, 3, 'p', '2004-12-01')
    insert into temp1 values (105, 1, 'c', '2005-10-01')
    insert into temp1 values (105, 2, 'p', '2005-11-01')
    insert into temp1 values (105, 3, 'c', '2005-12-01')
    insert into temp1 values (106, 1, 'c', '2006-08-01')
    insert into temp1 values (106, 2, 'p', '2006-09-01')
    insert into temp1 values (106, 3, 'c', '2006-10-01')
    insert into temp1 values (106, 4, 'p', '2006-11-01')
    insert into temp1 values (106, 5, 'p', '2006-12-01')
    select * from temp1
    order by id, ord
    --result expected:-
    create table temp1_result
    (id int,
    ord int,
    typ varchar(2),
    dt date)
    insert into temp1_result values (101, 1, 'c', '2001-10-01')
    insert into temp1_result values (101, 2, 's', '')
    insert into temp1_result values (101, 3, 'p', '2001-11-11')
    insert into temp1_result values (102, 1, 'c', '2002-10-01')
    insert into temp1_result values (102, 2, 's', '')
    insert into temp1_result values (102, 3, 'p', '2002-11-01')
    insert into temp1_result values (102, 4, 'p', '2002-12-01')
    insert into temp1_result values (103, 1, 'c', '2003-10-01')
    insert into temp1_result values (103, 2, 's', '')
    insert into temp1_result values (103, 3, 'p', '2003-11-01')
    insert into temp1_result values (104, 1, 'c', '2004-10-01')
    insert into temp1_result values (104, 2, 'c', '2004-11-01')
    insert into temp1_result values (104, 3, 's', '')
    insert into temp1_result values (104, 4, 'p', '2004-12-01')
    insert into temp1_result values (105, 1, 'c', '2005-10-01')
    insert into temp1_result values (105, 2, 's', '')
    insert into temp1_result values (105, 3, 'p', '2005-11-01')
    insert into temp1_result values (105, 4, 'c', '2005-12-01')
    insert into temp1_result values (106, 1, 'c', '2006-08-01')
    insert into temp1_result values (106, 2, 's', '')
    insert into temp1_result values (106, 3, 'p', '2006-09-01')
    insert into temp1_result values (106, 4, 'c', '2006-10-01')
    insert into temp1_result values (106, 5, 's', '')
    insert into temp1_result values (106, 6, 'p', '2006-11-01')
    insert into temp1_result values (106, 7, 'p', '2006-12-01')
    select * from temp1_resultregards
    Edited by: @2**** on 31-Jan-2012 06:48

    Well, in an Oracle database, something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with temp as (select 101 as id, 1 as ord, 'c' as typ, date '2001-10-01' as dt from dual union all
      2                select 101, 2, 'p', date '2001-11-11' from dual union all
      3                select 102, 1, 'c', date '2002-10-01' from dual union all
      4                select 102, 2, 'p', date '2002-11-01' from dual union all
      5                select 102, 3, 'p', date '2002-12-01' from dual union all
      6                select 103, 1, 'c', date '2003-10-01' from dual union all
      7                select 103, 2, 'p', date '2003-11-01' from dual union all
      8                select 104, 1, 'c', date '2004-10-01' from dual union all
      9                select 104, 2, 'c', date '2004-11-01' from dual union all
    10                select 104, 3, 'p', date '2004-12-01' from dual union all
    11                select 105, 1, 'c', date '2005-10-01' from dual union all
    12                select 105, 2, 'p', date '2005-11-01' from dual union all
    13                select 105, 3, 'c', date '2005-12-01' from dual union all
    14                select 106, 1, 'c', date '2006-08-01' from dual union all
    15                select 106, 2, 'p', date '2006-09-01' from dual union all
    16                select 106, 3, 'c', date '2006-10-01' from dual union all
    17                select 106, 4, 'p', date '2006-11-01' from dual union all
    18                select 106, 5, 'p', date '2006-12-01' from dual)
    19  --
    20  -- end of test data
    21  --
    22  select id
    23        ,row_number() over (partition by id order by ord, typ) as ord
    24        ,typ
    25        ,dt
    26  from (
    27        select id
    28              ,ord
    29              ,case when rn = 2 and add_typ = 's' then add_typ else typ end as typ
    30              ,case when rn = 1 then dt else null end as dt
    31        from (
    32              select t.id, t.ord, t.typ, t.dt
    33                    ,case when typ = 'c' and lead(typ) over (partition by id order by ord) = 'p' then 's'
    34                     else null end as add_typ
    35              from   temp t
    36             ) x
    37             cross join (select rownum rn from dual connect by rownum <= 2)
    38        where not (rn = 2 and add_typ is null)
    39       )
    40* order by id, ord
    SQL> /
            ID        ORD T DT
           101          1 c 01-OCT-2001 00:00:00
           101          2 s
           101          3 p 11-NOV-2001 00:00:00
           102          1 c 01-OCT-2002 00:00:00
           102          2 s
           102          3 p 01-NOV-2002 00:00:00
           102          4 p 01-DEC-2002 00:00:00
           103          1 c 01-OCT-2003 00:00:00
           103          2 s
           103          3 p 01-NOV-2003 00:00:00
           104          1 c 01-OCT-2004 00:00:00
           104          2 c 01-NOV-2004 00:00:00
           104          3 s
           104          4 p 01-DEC-2004 00:00:00
           105          1 c 01-OCT-2005 00:00:00
           105          2 s
           105          3 p 01-NOV-2005 00:00:00
           105          4 c 01-DEC-2005 00:00:00
           106          1 c 01-AUG-2006 00:00:00
           106          2 s
           106          3 p 01-SEP-2006 00:00:00
           106          4 c 01-OCT-2006 00:00:00
           106          5 s
           106          6 p 01-NOV-2006 00:00:00
           106          7 p 01-DEC-2006 00:00:00
    25 rows selected.

  • How to add a Totals row in a dashboard

    Oracle Business Intelligence 11.1.1.6.4
    Hi there gurus,
    I would like to know how to add a totals row at the end of a pivot table within a dashboard. Notice that the column I need to sum up is a measure column and not a dimension one.
    Thank a lot.

    Alejandro Trejo wrote:
    Oracle Business Intelligence 11.1.1.6.4
    Hi there gurus,
    I would like to know how to add a totals row at the end of a pivot table within a dashboard. Notice that the column I need to sum up is a measure column and not a dimension one.
    Thank a lot.What do you mean? That's what you would always expect to aggregate. Click the sigma sign on the Rows section and it will sum up the measures column. If not, add the aggregation rule to the measure column. Otherwise, explain IN DETAIL what you did, don't assume that what you did was correct.

  • How to pass one row of a result set to a cffunction?

    I can pass the entire result set of a query to a cffunction,
    but the function only needs one row.
    The code below is a syntax error, where "3" is array index
    notation for the third row of the result set.
    What is the correct way to pass one row of a result set to a
    cffunction?
    Thank you.

    iirc, cf does not allow one to reference and access a row of
    a resultset
    like that.
    you will have to create a structure/array that holds the data
    from
    specific query row and pass that to your function. looping
    over
    queryname.columnlist list will make it easier and not
    specific to any
    particular query. make it into another function that accepts
    a query and
    row number as arguments and returns a struct/array of that
    row data (or
    automatically passes it to another function).
    sample code for creating a structure of specific query row
    data:
    <cfset rowstruct = {}>
    <cfloop list="#queryname.columnlist#" index="col">
    <cfset rowstruct[col] = queryname[col][somerownumber]>
    </cfloop>
    <cfdump var="#rowstruct#">
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

  • OBIEE Answers does not display the result set of a report query

    Hi,
    We have a pivot table type of report in Oracle Business Intelligence Enterprise Edition v.10.1.3.3.2 Answers that has the following characteristics:
         3 Pages
         3 Sections , 4 Columns
         18363 Rows in the result set
    As per the NQQuery.log, the query for this report executes successfully resulting in 18363 rows. However, nothing comes up in the display on Answers. Moreover, no error is reported. The instanceconfig.xml file has the following setting:
    <PivotView>
         <CubeMaxRecords>30000</CubeMaxRecords>
         <CubeMaxPopulatedCells>300000</CubeMaxPopulatedCells>
    </PivotView>
    Even with these settings, Answers just returns a blank page - nothing is displayed in the name of the result set of the report query. Has anyone encountered this problem scenario before?
    Any help is much appreciated.
    Thanks,
    Piyush

    Hi Fiston / Pradeep,
    Thanks for your inputs. A few points to note:
    -> I am actually not getting any error message in answers or the NQQuery log. Moreover I am not getting any errors related to "query governor limit exceeding in cube generation" also.
    -> I have other pivot table type of reports in the same repository that work fine. In fact the report which has this issue even works sometimes - what actually is happening is that if I alter the number of sections from 3 to 4, then the result set changes from 14755 Rows to 18363 Rows and as per the NQQuery.log in both cases the query completes successfully. However, when the result set has 14755 rows, I get to see the output in Answers; however when the result set is 18636 rows, the Answers screen just goes blank and does not show any output or error. This makes me believe that there is some parameter in instanceconfig or the NQSconfig file - I have tried a lot of changes but nothing works !
    Any help is much appreciated.
    Best Regards,
    Piyush

Maybe you are looking for