Sum problem of rows because of column

Problem...
I have 2 row groups
Year and QTY
for every Year (2003,2004 etc) there are a number of cities with their own QTY
For instance
City1 has QTY = 20 for Year 2003
City2 has QTY = 30 for Year 2003
When I sum only one City1 I want the column QTY to show 20 for Year 2003 and to show 50 if both City1 and City2 are selected.
The problem is when I sum let say City 1 it shows me 100 instead of 20 because the column group consists of 5 rows in dataset query with QTY 20, so if I sum 2 cities of the same Year it will give me 100(City1) + X(City2).   
Did it make sense or do you need more input?

Hi Jhonny86,,
According to your description, you want to sum the [Qty] values for based on the selected values in the parameter.
In your scenario, you can use DISTINCT keyword to return only distinct (different) values in query designer. Then create a tablix group on [Year] and create a city parameter. Please refer to screenshots below:
If report deisgn above doesn't meet your requirements, please share sample data and expected results for our analysis.
If you have any question, please feel free to ask.
Best regards,
Qiuyun Yu
Qiuyun Yu
TechNet Community Support

Similar Messages

  • SQL Developer problem. Rows without columns on data tab

    Hello,
    I have a strange behavior in Oracle SQL Developer Version 2.1.0.63. When I'm trying to open the "Data tab" for some tables, SQL Developer shows data rows but without columns! It seems that I can select different rows but I can't see neither any data nor column names.
    Under the filter setting there are no available columns either.
    At the same time, when I'm trying to open sys tables they are displayed normally.
    From the other side, those tables which are not displayed correctly in 2.1.0.63, could be opened in Version 1.5.5 without any problems.
    Do you have any ideas?
    Thanks in advance.

    Hi,
    Refer to the SQL Developer forum: SQL Developer for SQL Developer related questions

  • How to get sum in new row (not in a new column) in the query output ?

    There are values in a table like this:
    A B C D
    DEsc1 ID1 15 45
    DEsc2 ID1 10 67
    DEsc3 ID2 12 34
    Desc4 ID2 19 32
    How to achieve this output :
    A B C D
    DEsc1 ID1 15 45
    DEsc2 ID1 10 67
    --- ID1 25 112 <--- Sum of two rows corresponding to C and D whose B column is same
    DEsc3 ID2 12 34
    Desc4 ID2 19 32
    Desc5 ID2 10 12
    ----- ID2 41 78 <---- Sum of three rows corresponding to C and D whose B column is same

    SQL>WITH t AS
      2       (SELECT 'DEsc1' AS a, 'ID1' AS b, 15 AS c, 45 AS d FROM DUAL
      3        UNION ALL
      4        SELECT 'DEsc2', 'ID1', 10, 67 FROM DUAL
      5        UNION ALL
      6        SELECT 'DEsc3', 'ID2', 12, 34 FROM DUAL
      7        UNION ALL
      8        SELECT 'Desc4', 'ID2', 19, 32 FROM DUAL)
      9  SELECT   DECODE(GROUPING(a || ' ' || c || ' ' || d), 0, TO_CHAR(MAX(a)), '-----') AS a,
    10           MAX(b) AS b, SUM(c) AS c, SUM(d) AS d
    11      FROM t
    12  GROUP BY b, ROLLUP(a || ' ' || c || ' ' || d);
    A     B            C          D
    DEsc1 ID1         15         45
    DEsc2 ID1         10         67
    ----- ID1         25        112
    DEsc3 ID2         12         34
    Desc4 ID2         19         32
    ----- ID2         31         66Urs

  • SUM problem in SSRS 2005 report

    I don't know how best to explain this but will try.
    In my SSRS 2005 report, i have one group in my table.  In that group, I have a field that for each company record in my dataset, this field value is repeated for each record. This is a transactions table so you'd expect several records in the dataset for each company..that's not the problem.
    example data from dataset:
    TransID     CompanyID      FeeGoal
    1                1000                  100
    2                1000                  100
    3                1000                  100
    4                2000                   400
    5                2000                   400
    My SSRS 2005 Report has:
    Group1 fields:
    CompanyID                                       FeeGoal
    =Fields!CustomerNumber.Value        =Fields!FeeGoal.Value
    The output when previewed looks like this:
    Company   FeeGoal
    1000               100
    2000               400
    Footer            209409730.83 (totals up all feegoals!  not just unique instances!)
    I have a footer, and this is where the problem comes in.  I am not able to sum 100 + 400 because if I do a SUM(=Fields!FeeGoal.Value) It doesn't just sume up 100 + 400 but rather (100 + 100 + 100) + (400 + 400)
    I can't find a way to sum up basically the top values for FeeGoal which is really what the Group Field is doing since I get 100 and 400 in my group field for feeGoal.  I should end up with a total of 500 for my footer total for Fee Goal but not sure how to get this to work in this unique situation.
    FYI: FeeGoal is an input from an ASP.NET form to allow managers to update that one column in my report so that other calculations can rely on it in my group fields.  Once the user finishes, I run a stored proc to insert that fee goal in every customer transaction record / feegoal field
    I guess is there a way to do some sort of Distinct SUM in an expression? I also tried:
    =SUM((Max(Fields!FeeGoal_AZ.Value)) / Fields!FeeSchedule.Value) * 100)
    but you can't have an aggregate function like this, I get this error:
    [rsAggregateofAggregate] The Value expression for the textbox 'GrossGoal_gt' contains an aggregate function (or RunningValue or RowNumber functions) in the argument to another aggregate function (or RunningValue). Aggregate functions cannot be nested inside other aggregate functions.
    Build complete -- 1 errors, 0 warnings
     

    Hi,
    I need to generate a SSRS 2005 report like bellow:
    OrderNumber    MultiInvoice    SalesAmt        
    TaxAmt          TotalAmt
    301256              1                     
    302                   20                  322
    369856                                    
     501                   10                  511
    359826                                    
    456                    1                    457
    785412              2                    
    725                    25                  750
    totalRow=4      totalRow=2      Sum=1984        Sum=56          
    Sum=2040 ----------------------->Footer
    --I added textbox in ther footer of that report table, and try to add expression for each, like
    1>OrderNumber : =CountRows()
    2>MultiInvoice :  =Count(column name) //but it is return no of rows,
    where it should be only 2.
    How can do that?
    3>SalesAmt : =
    SUM(Fields!SalesAmt.Value)   //It is not returning actual summation of all rows for
    SalesAmt
     column. How can I do that?
    Dipen Bhadra

  • More Rows or More Columns ?

    I have a table (a form) where 50 attributes have to be filled for each id. There may be some extra attributes be added or removed in this form.
    Which is better
    1) Going with more columns (50+) less rows.
    2) Going with less columns and more rows.
    I am more inclined towards more rows because of the main disadvantage of adding and removing the columns.
    Any descriptive answer will be of good help (any reference will also do good)

    CP wrote:
    Can you please elaborate on this. I have tried 2NF before but not 3NF.It actually sounds as though you are trying to design your database using some form of Entity Attribute Value (EAV) model, where you store a row for each attribute of an entity.
    e.g.
    +-----------+--------------+-----------------------+
    | Entity_ID | Attribute_ID | Attribute Value       |
    +-----------+--------------+-----------------------+
    |         1 |            1 | Mr.                   |
    |         1 |            2 | John                  |
    |         1 |            3 | Smith                 |
    |         2 |            1 | Mr.                   |
    |         2 |            2 | Joe                   |
    |         2 |            3 | Bloggs                |
    |         3 |            1 | Mrs                   |
    |         3 |            2 | Tiggy                 |
    |         3 |            3 | Winkle                |
    +-----------+--------------+-----------------------+This apparently makes for a very flexible data model because, if you need to add more attributes for an entity, we can just assign another Attribute_ID for this new attribute (e.g. 4 for a persons date of birth) and then store rows with data for those attributes.
    The problem with this however is that it is not using a relational database in the best way, and leads to major overheads in programming and consildating the data back to the single entity. EAV models have very few valid uses, and have been tried by many in the past to create "generic" or "flexible" database designs, typcially ending in disaster.
    Here's a good story to illustrate a company that had a developer create them an EAV model database...
    http://www.simple-talk.com/opinion/opinion-pieces/bad-carma/
    The proper design for a database would put all the attributes for an entity as individual columns on a single row. The required attributes should be known about at design time so, in most cases, there shouldn't be much need later on to add new attributes, and if there is, it's usually easy enough to add a new column to the table to cater for it, or in some cases create another relational table store the additional attribute(s) (especially if there is several attributes to be added). This is the nature of 3rd normal form (3NF)...
    http://en.wikipedia.org/wiki/Third_normal_form

  • Applying table scroll bar for only table rows with table columns fixed.

    hi oa gurus,
    i had implemented table scroll bars using oarawtextbean , there is no problem in vertical and horizontal scroll bar working its working fine. but the requirement is i need to scroll only the table rows with table columns fixed. so , how to achieve the table scroll for only table datas neglecting table headers.
    the code for vertical and horizontal bars scroll is like this,
    OARawTextBean ors = (OARawTextBean)webBean.findChildRecursive("raw1");
    ors.setText(div id=tabledivid style=height:500px;width:100%; overflow:auto>);
    OARawTextBean ore = (OARawTextBean)webBean.findChildRecursive("raw2");
    ore.setText("</div>");
    where raw1 and raw2 are rawtextbean created above and below of the table . but i dont know hoow to apply this only for table rows neglecting table columns , can anybody give any ideas.
    pelase this is very urgent , can u help me in this regards
    thanks
    Edited by: user630121 on Sep 29, 2008 5:17 AM
    Edited by: user630121 on Sep 29, 2008 5:18 AM

    hi,
    I have a similar task to do... Only to apply scrollbar at the table level.
    I tried using the above mentioned but I am facing Null Pointer Exception..
    Please explain about raw1 and raw2
    Rahul

  • Count the no. of rows in a column

    I want to count the no. of rows in APR_QTY column that are not equal to zero.
    SELECT DISTINCT
    SUPP_NAME,
    ITEM_NAME,
    (CASE WHEN BH_CAL_PERIOD=4 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)APR_QTY,
    (CASE WHEN BH_CAL_PERIOD=4 THEN BI_RATE ELSE 0 END)APR_RATE,
    (CASE WHEN BH_CAL_PERIOD=5 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)MAY_QTY,
    (CASE WHEN BH_CAL_PERIOD=5 THEN BI_RATE ELSE 0 END)MAY_RATE,
    (CASE WHEN BH_CAL_PERIOD=6 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUNE_QTY,
    (CASE WHEN BH_CAL_PERIOD=6 THEN BI_RATE ELSE 0 END)JUNE_RATE,
    (CASE WHEN BH_CAL_PERIOD=7 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUL_QTY,
    (CASE WHEN BH_CAL_PERIOD=7 THEN BI_RATE ELSE 0 END)JUL_RATE
    FROM
    OM_SUPPLIER,
    OM_ITEM,
    OT_BILL_HEAD,
    OT_BILL_ITEM,
    OT_BILL_ITEM_TED
    WHERE BI_BH_SYS_ID = BH_SYS_ID
    AND SUPP_CODE = BH_SUPP_CODE
    AND ITEM_CODE = BI_ITEM_CODE
    AND BH_SYS_ID = ITED_H_SYS_ID
    AND BI_SYS_ID = ITED_I_SYS_ID
    AND BH_TXN_CODE='SBRLRAW'
    GROUP BY BH_CAL_PERIOD,BH_TXN_CODE,SUPP_NAME,ITEM_NAME,BI_RATE,BI_QTY,BI_QTY_LS
    ORDER BY ITEM_NAME
    Message was edited by:
    yogeshyl

    Select sum(decode(apr_qty,0,0,1)) as cnt_apr_qty
    from ...

  • Problem with attachtment XLS (last column of the xls)

    Hi,
    iam working on interface in which i will be sending an email along with attachtment where my email along with attachtment are working perfectly ,the problem is with the XLS where the last column of the XLS is taking 255 char which is the length of the field .
    How i have to  restrict it ?
    solution on this would be helpfull .
    Thanks ,
    shankar.
    I have attached the sample code too.
    FUNCTION zemail_send_attachment.
    ""Local Interface:
    *" IMPORTING
    *" VALUE(EMAILID)
    *" VALUE(SUBJECT)
    *" VALUE(ATYPE)
    *" TABLES
    *" ATTACH_FILE STRUCTURE SOLISTI1
    *" BODY OPTIONAL
    This table requires information about how the data in the
    tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are
    to be distributed to the documents and its attachments.
    DATA objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
    This table must contain the summarized data dependent on each object type.
    SAPscript objects store information here about forms and styles,
    for example. Excel list viewer objects store the number of rows and columns
    amongst other things and PC objects store their original file name.
    DATA objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
    This table must contain the summarized content of the objects identified as binary objects.
    DATA objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
    WITH HEADER LINE.
    This table must contain the summarized content of the objects identified as ASCII objects.
    DATA objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
    This table must contain the document recipients.
    DATA reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE .
    This structure must contain the attributes of the document to be sent.
    DATA: doc_ching LIKE sodocchgi1.
    DATA: tab_lines LIKE sy-tabix.
    Create the internal table for body , subject
    DATA: it_body LIKE solisti1 OCCURS 10 WITH HEADER LINE.
    CONSTANTS: con_cret TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
    con_tab TYPE c VALUE cl_abap_char_utilities=>cr_lf.
    Move Body to Internal Table (body into it_body)
    LOOP AT body .
    MOVE body TO it_body .
    APPEND it_body .
    ENDLOOP.
    doc_ching-obj_descr = subject. "Subject of the Email
    Move the Subject and Body to OBJTXT
    objtxt[] = it_body[].
    DESCRIBE TABLE objtxt LINES tab_lines.
    READ TABLE objtxt INDEX tab_lines.
    doc_ching-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
    CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num = 0.
    objpack-body_start = 1.
    objpack-body_num = tab_lines.
    objpack-doc_type = 'RAW'.
    APPEND objpack.
    Convert IT to Excel format
    IF atype = 'XLS' .
    LOOP AT attach_file .
    REPLACE ALL OCCURRENCES OF '#' IN attach_file WITH con_cret ."INTO objbin.
    IF sy-tabix = 1.
    MOVE attach_file TO objbin.
    ELSE.
    CONCATENATE con_tab attach_file INTO objbin.
    ENDIF.
    APPEND objbin.
    ENDLOOP.
    ELSEIF atype = 'TXT' .
    Convert IT to Text format
    LOOP AT attach_file .
    REPLACE ALL OCCURRENCES OF '#' IN attach_file WITH con_cret. " INTO objbin.
    CONCATENATE attach_file con_tab INTO objbin .
    APPEND objbin .
    ENDLOOP.
    ENDIF.
    DESCRIBE TABLE objbin LINES tab_lines.
    objhead = subject. APPEND objhead.
    Creating the entry for the compressed attachment
    objpack-transf_bin = 'X'.
    objpack-head_start = 1.
    objpack-head_num = 1.
    objpack-body_start = 1.
    objpack-body_num = tab_lines.
    IF atype = 'XLS'.
    objpack-doc_type = atype.
    ELSEIF atype = 'TXT'.
    objpack-doc_type = 'RAW'.
    ENDIF.
    objpack-obj_name = 'ATTACHMENT'.
    objpack-obj_descr = 'TEST'. "Attachment File Name
    objpack-doc_size = tab_lines * 255.
    APPEND objpack..
    reclist-receiver = emailid.
    reclist-rec_type = 'U'.
    APPEND reclist.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = doc_ching
    put_in_outbox = 'X'
    commit_work = 'X'
    IMPORTING
    SENT_TO_ALL =
    NEW_OBJECT_ID =
    TABLES
    packing_list = objpack
    object_header = objhead
    contents_bin = objbin
    contents_txt = objtxt
    receivers = reclist
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    operation_no_authorization = 4
    OTHERS = 99 .
    ENDFUNCTION.

    I had this problem after migrating to JDeveloper 10.1.3. Problem was with inconsistent DB column types. In our case, the DB column was CHAR containing only numbers, but VO defined it as NUMBER. This caused no problem in 9.0.3 we used before.
       <ViewAttribute
          Name="ParentFlagNew"
          IsPersistent="false"
          Precision="1"
          Type="oracle.jbo.domain.Number"
          ColumnType="NUMBER"
          AliasName="PARENT_FLAG_NEW"
          Expression="PARENT_FLAG_NEW"
          SQLType="NUMERIC" >
          <Properties>
             <Property Name ="DISPLAY_LIST" Value ="1=Yes,0=No" />
             <Property Name ="DISPLAY_LIST_sk" Value ="1=Áno,0=Nie" />
             <Property Name ="Renderer" Value ="sk.transacty.cm_iface.bc4j_common.ListFieldRenderer" />
          </Properties>
          <DesignTime>
             <Attr Name="_DisplaySize" Value="1" />
          </DesignTime>
       </ViewAttribute>

  • Problem in summation on a column with possible null values

    Hi,
    I want to do summation on a column.
    If I use <?sum(amount)?>, if there is any null value,its giving NaN as output.
    From the forum I got the below syntax
    <?sum(AMOUNT[number(.)!='NaN'])?>
    but it is also not giving me the expected result. Its always displays 0.
    I want some thing like sum(NVL(amount,0)). Could some body please help me out?
    Thanks in Advance,
    Thiru

    If the column has many, many null values, and you want to use the index to identify the rows with non-null values, this is a good thing, as a B*Tree index will not index the nulls at all, so, even though your table may be very large, with many millions of rows, this index will be small and efficient, cause it will only contain index entries for those rows where the column is not null.
    Hope that helps,
    -Mark

  • I have 105 rows with alternating columns of No. sold

    I have 105 rows with alternating columns of No. Sold and Amount Sold, for six different dates.  I want the two totals columns on the right to sum every other column for the Total No. Sold and the same but one over for Total Amount Sold.  I know how to do this for a single row, as I have done for the last totals row.  How could I do the formula for all rows without entering it for each one, or if that is not possible, maybe I could copy the formula in some way to make it easier?

    rogerfrombellingham wrote:
    ...  I know how to do this for a single row, as I have done for the last totals row.  How could I do the formula for all rows without entering it for each one, or if that is not possible, maybe I could copy the formula in some way to make it easier?
    Yes, Roger, you can easily copy those formulas for all the rest of the 105 rows.
    Select the two totals cells, click on the little circle in the lower right corner of the selection and drag it to the bottom.
    Jerry

  • Convert rows to single column using t-sql

    Hi All,
    I have a table with 7 columns, et say..
      ID ,PatientName,Date,Time,Room_Num ,Specialized, DoctorName
    My source date looks like this..
      ID      PatientName     Date          Time    Room_Num  Specialized   DoctorName
       1         Sam        10/02/2010      10:00     4         Heart        
    John
       1         Sam        10/02/2010      10:00     4         Lungs        
    Harris
       2         Jones      11/12/2011      11:00     1         Lungs        
    Bob
       3         Jim        12/05/2001      01:00     2         Kidney       
    Greg
       3         Jim        12/05/2001      09:00     2         Eye          
    Roby
       1         Sam        12/22/2010      11:00     1         Heart        
    John
       1         Sam        12/22/2010      11:00     1         Lungs        
    Harris
    My out put should look like this..
       ID      PatientName     Date             DoctorName
       1         Sam        10/02/2010           John,Harris ( Need to be in 1 row because - ID, PatientName, Date is same)
       2         Jones      11/12/2011            Bob       ( Need to show as it is due to no repeatition
    of ID)
       3         Jim        12/05/2001            Greg,Roby   ( Need to be in 1 row because - ID, PatientName,
    Date is same)
       1         Sam        12/22/2010            John,Harris ( Need to be in 1 row because - ID, PatientName, Date is same)
    I am using below query to get above results but I am getting wrong results..Need some help in tweaking the query...
     SELECT DISTINCT ID ,PatientName , Date 
             ,STUFF(( SELECT ',' + DoctorName 
              FROM SampleTable ST1
              WHERE ST1.ID=ST2.ID
              FOR XML PATH('')),1,1,' ') AS DoctorName
              FROM SampleTable1 ST2
    GROUP BY ID ,PatientName , Date
    With above query I am getting results like this...
      ID      PatientName     Date             DoctorName
       1         Sam        10/02/2010         John,Harris ,John,Harris ( here John,Harris are repeating twice because of 4th row)
       2         Jones      11/12/2011         Bob      
       3         Jim        12/05/2001         Greg,Roby   
       1         Sam        12/22/2010         John,Harris ,John,Harris ( here John,Harris are repeating twice because of 1st row)
    Create table statement:
    Create table SampleTable
    ID Int null,     PatientName  varchar(25) null,   Date  datetime null,  Time varchar(10) null,   Room_Num int null, Specialized  varchar(20) null, DoctorName varchar(20) null
    Insert statement:
    Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam','10/02/2010' ,'10:00',4 ,'Heart','John')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1, 'Sam','10/02/2010' ,'10:00'   ,  4    ,     'Lungs','Harris')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 2, 'Jones' ,'11/12/2011'  ,    '11:00',1, 'Lungs',  'Bob')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values  ( 3,'Jim' ,'12/05/2001'    ,  '01:00',2,'Kidney' ,  'Greg')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 3,'Jim' ,'12/05/2001'     , '09:00',2,'Eye' ,   'Roby')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam' ,'12/22/2010'     , '11:00',1,'Heart', 'John')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam', '12/22/2010'     , '11:00',1 , 'Lungs','Harris')
    I need help to tweak my query.
    Thanks,
    RH
    sql

    WITH cte AS(
    SELECT [ID]
    ,[PatientName]
    ,[Date]
    ,[Time]
    ,[Room_Num]
    ,[Specialized]
    ,[DoctorName]
    ,ROW_NUMBER() OVER(PARTITION BY [ID],[PatientName],[Date] ORDER BY Time) as RowID
    FROM [test].[dbo].[SampleTable]
    SELECT
    cte.[ID]
    ,cte.[PatientName]
    ,CAST(cte.[Date] as DATE) as [Date]
    ,STUFF((SELECT ',' + c.[DoctorName]
    FROM cte c
    WHERE c.ID=cte.ID AND c.PatientName=cte.[PatientName] AND c.[Date]=cte.[Date]
    FOR XML PATH(''),TYPE).value('.','varchar(max)')
    ,1,1,'') AS [DoctorName]
    FROM cte
    WHERE cte.RowID=1

  • Schema Design for 10^6+ rows table (Indicator Column / Bitmap Join Index?)

    Hi all,
    I read following suggestion for a SELECT with LEFT OUTER JOIN in a DB2 consulting company paper for a 10 million-rows table:
    SELECT columns
    FROM ACCTS A LEFT JOIN OPT1 O1
    ON      A.ACCT_NO = O1.ACCT_NO
    AND     A.FLAG1 = ‘Y’
    LEFT JOIN OPT2 O2
    ON      A.ACCT_NO = O2.ACCT_NO
    AND     A.FLAG2 = ‘Y’
    WHERE A.ACCT_NO = 1
    For DB2, according to the paper, the following is true: Iff A.FLAG1 <> ‘Y’ Then no Table or Index Access on OPT1 is done. Same for A.FLAG2/OPT2.
    I recreated the situation for ORACLE with the following script and came to some really interesting questions
    DROP TABLE maintbl CASCADE CONSTRAINTS;
    DROP TABLE opt1 CASCADE CONSTRAINTS;
    DROP TABLE opt2 CASCADE CONSTRAINTS;
    CREATE TABLE maintbl
    id INTEGER NOT NULL,
    dat VARCHAR2 (2000 CHAR),
    opt1 CHAR (1),
    opt2 CHAR (1),
    CONSTRAINT CK_maintbl_opt1 CHECK(opt1 IN ('Y', 'N')) INITIALLY IMMEDIATE ENABLE VALIDATE,
    CONSTRAINT CK_maintbl_opt2 CHECK(opt2 IN ('Y', 'N')) INITIALLY IMMEDIATE ENABLE VALIDATE,
    CONSTRAINT PK_maintbl PRIMARY KEY(id)
    CREATE TABLE opt1
    maintbl_id INTEGER NOT NULL,
    adddat1 VARCHAR2 (100 CHAR),
    adddat2 VARCHAR2 (100 CHAR),
    CONSTRAINT PK_opt1 PRIMARY KEY(maintbl_id),
    CONSTRAINT FK_opt1_maintbltable FOREIGN KEY(maintbl_id) REFERENCES maintbl(id)
    CREATE TABLE opt2
    maintbl_id INTEGER NOT NULL,
    adddat1 VARCHAR2 (100 CHAR),
    adddat2 VARCHAR2 (100 CHAR),
    CONSTRAINT PK_opt2 PRIMARY KEY(maintbl_id),
    CONSTRAINT FK_opt2_maintbltable FOREIGN KEY(maintbl_id) REFERENCES maintbl(id)
    INSERT ALL
    WHEN 1 = 1 THEN
    INTO maintbl (ID, opt1, opt2, dat) VALUES (nr, is_even, is_odd, maintbldat)
    WHEN is_even = 'N' THEN
    INTO opt1 (maintbl_id, adddat1, adddat2) VALUES (nr, adddat1, adddat2)
    WHEN is_even = 'Y' THEN
    INTO opt2 (maintbl_ID, adddat1, adddat2) VALUES (nr, ADDdat1, ADDdat2)
    SELECT LEVEL AS NR,
    CASE WHEN MOD(LEVEL, 2) = 0 THEN 'Y' ELSE 'N' END AS is_even,
    CASE WHEN MOD(LEVEL, 2) = 1 THEN 'Y' ELSE 'N' END AS is_odd,
    TO_CHAR(DBMS_RANDOM.RANDOM) AS maintbldat,
    TO_CHAR(DBMS_RANDOM.RANDOM) AS adddat1,
    TO_CHAR(DBMS_RANDOM.RANDOM) AS adddat2
    FROM DUAL
    CONNECT BY LEVEL <= 100;
    COMMIT;
    SELECT * FROM maintbl
    LEFT OUTER JOIN opt1 ON maintbl.id = opt1.maintbl_id AND maintbl.opt1 = 'Y'
    LEFT OUTER JOIN opt2 ON maintbl.id = opt2.maintbl_id AND maintbl.opt2 = 'Y'
    WHERE id = 1;
    Explain plan for "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi":
    http://i.imgur.com/f0AiA.png
    As one can see, the DB uses a view to index-access the opt tables iff indicator column maintbl.opt1='Y' in the main table.
    Explain plan for "Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production":
    http://i.imgur.com/iKfj8.png
    As one can see, the DB does NOT use the view, instead uses a pretty useless case-statement
    Now my questions:
    1) What does the optimizer do in 11.2 XE?!?
    2) In General: Do you suggest this table-setup? Does your yes/no suggestion depend on the rowcount in the tables? Of course I see the problem with incorrectly updated columns and would NEVER do it if there is another truly relational solution with same performance possibly.
    3) Is there a way to avoid performance issues if I don't use an indicator column in ORACLE? Is this what a [Bitmap Join Index|http://docs.oracle.com/cd/E11882_01/server.112/e25789/indexiot.htm#autoId14] is for?
    Thanks in advance and happy discussing,
    Blama

    Fair enough. I've included a cut-down set of SQL below.
    CREATE TABLE DIMENSION_DATE
    DATE_ID NUMBER,
    CALENDAR_DATE DATE,
    CONSTRAINT DATE_ID
    PRIMARY KEY
    (DATE_ID)
    CREATE UNIQUE INDEX DATE_I1 ON DIMENSION_DATE
    (CALENDAR_DATE, DATE_ID);
    CREATE TABLE ORDER_F
    ORDER_ID VARCHAR2(40 BYTE),
    SUBMITTEDDATE_FK NUMBER,
    COMPLETEDDATE_FK NUMBER,
    -- Then I add the first bitmap index, which works:
    CREATE BITMAP INDEX SUBMITTEDDATE_FK ON ORDER_F
    (DIMENSION_DATE.DATE_ID)
    FROM ORDER_F, DIMENSION_DATE
    WHERE ORDER_F.SUBMITTEDDATE_FK = DIMENSION_DATE.DATE_ID;
    -- Then attempt the next one:
    CREATE BITMAP INDEX completeddate_fk
    ON ORDER_F(b.date_id)
    FROM ORDER_F, DIMENSION_DATE b
    WHERE ORDER_F.completeddate_fk = b.date_id;
    -- which results in:
    -- ORA-01408: such column list already indexed

  • Matrix row grand total, column grand total

    matrix report layout in sql 2008
    report shows     column a   column b    column c    total
              row 1           4              5             
    8             17
              row 2           3              5             
    2             10
              row 3           2              7             
    6             15
    total                      9              17           
    16      grand total column 42
    grand total row 42
    How do I define the grand total cells to use column totals or row totals?  Not just the sum of field in dataset?
    Accounting wants justification that column totals add up to row totals.

    Hi JimHoopsDSC,
    Based on my understanding, you want to show grand total columns and grand total rows in the report.
    For your requirement, you can create a matrix and add total for row groups and column groups. Then you can add an additional row and populate the total value. Please refer to screenshots below:
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • Table Rendering - Row level vs Column level

    Normally renderers are specified for a given class of data or column of data.
    So, how would you handle rendering requirements that are row or table dependent? For example, how do I:
    a) color alternate lines in a table
    b) change the border of the selected cell
    Traditional Approach
    Most answers in the forum would be something like "use a custom render". Sounds great, but what does it really mean? If all your data is displayed as a String then it really isn't too difficult to create a single renderer with the required logic and add it to the table as the default renderer.
    However, what if you table contains, String's, Dates, Integer's, Double's and Boolean's and you want your cell to retain the default formatting of each data type in addition to the above requirement? Now you have two options:
    a) render by class (multiple renderers). Each renderer would need to implement the default "formatting" of the data (dates: dd-MMM-yyy, numbers: right justified, etc) in addition to the "row/table" rendering requirements. So the answer really becomes "use five custom renderers". Now the "row/table" rendering code is found in 5 classes. Of course you could always move the "row/table" rendering code up to a common base class.
    b) render by table (single renderer). A single custom renderer would be created and would need to implement the default "formatting" for all data types in the table, in addition to the "row/table" rendering. The benefit is that all the rendering code is in one class. An example solution is include for this approach.
    Alternative Approach
    I recently came across an approach where the "formatting" of the data is still done by the default renderers and the "row/table" rendering is done at the table level by overriding the prepareRenderer() method. This approach is much simpler, but the rendering is done in two different places. Is this a problem?
    So, my question is which approach do you prefer:
    a) Traditional Approach - multiple renderers
    b) Triditional Approach - single renderer
    c) Alternative Approach
    Me, I like the alternative approach, but I'm more of a problem solver than I am a designer, so I don't know how the solution fits in a large scale application.
    Hopefully your response will consider:
    a) OO design principles
    b) class reusability
    c) class maintenance
    d) anything else you can think of
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class TableRowRendering extends JFrame
        JTable table;
        Border selected = new LineBorder(Color.GREEN);
        public TableRowRendering()
            //  Model used by both tables
            Object[] columnNames = {"Type", "Date", "Company", "Shares", "Price"};
            Object[][] data =
                {"Buy", new Date(), "IBM", new Integer(1000), new Double(80.50)},
                {"Sell",new Date(), "MicroSoft", new Integer(2000), new Double(6.25)},
                {"Sell",new Date(), "Apple", new Integer(3000), new Double(7.35)},
                {"Buy", new Date(), "Nortel", new Integer(4000), new Double(20.00)}
            DefaultTableModel model = new DefaultTableModel(data, columnNames)
                public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
            //  Traditional Approach
            table = new JTable( model );
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            getContentPane().add(new JScrollPane( table ), BorderLayout.WEST);
            TableCellRenderer custom = new CustomRenderer();
            table.setDefaultRenderer(Object.class, custom);
            table.setDefaultRenderer(String.class, custom);
            table.setDefaultRenderer(Date.class, custom);
            table.setDefaultRenderer(Number.class, custom);
            table.setDefaultRenderer(Double.class, custom);
            //  Alternative Approach
            table = new JTable( model )
                public Component prepareRenderer(
                    TableCellRenderer renderer, int row, int column)
                    Component c = super.prepareRenderer(renderer, row, column);
                    if (!isRowSelected(row))
                        String type = (String)getModel().getValueAt(row, 0);
                        c.setBackground(row % 2 == 0 ? null : Color.LIGHT_GRAY );
                    if (isRowSelected(row) && isColumnSelected(column))
                        ((JComponent)c).setBorder(selected);
                    return c;
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            getContentPane().add(new JScrollPane( table ), BorderLayout.EAST);
        //  Custom renderer used by Traditional approach
        class CustomRenderer extends DefaultTableCellRenderer
            DateFormat dateFormatter = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
            NumberFormat numberFormatter = NumberFormat.getInstance();
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column)
                super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column);
                //  Code for data formatting
                setHorizontalAlignment(SwingConstants.LEFT);
                if ( value instanceof Date)
                    setText(dateFormatter.format((Date)value));
                if (value instanceof Number)
                    setHorizontalAlignment(SwingConstants.RIGHT);
                    if (value instanceof Double)
                        setText(numberFormatter.format(((Number) value).floatValue()));
                //  Code for highlighting
                if (!isSelected)
                    String type = (String)table.getModel().getValueAt(row, 0);
                    setBackground(row % 2 == 0 ? null : Color.LIGHT_GRAY );
                if (table.isRowSelected(row) && table.isColumnSelected(column))
                    setBorder(selected);
                return this;
        public static void main(String[] args)
            TableRowRendering frame = new TableRowRendering();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }Before you make your final decision. What changes would be required for each solution in the following "what if " scenarios:
    a) what if, you added a Boolean column to the table
    b) what if, you added a second Double column to the table which should be formatted as a currency (ie. 1,234.5 --> $1,234.50).
    Here is an example of a currency renderer:
    class CurrencyRenderer extends DefaultTableCellRenderer
         private NumberFormat formatter;
         public CurrencyRenderer()
              super();
              formatter = NumberFormat.getCurrencyInstance();
              setHorizontalAlignment( SwingConstants.RIGHT );
         public void setValue(Object value)
              if ((value != null) && (value instanceof Number))
                   value = formatter.format(value);
              super.setValue(value);
    }

    Well, here's a partila solution using technique from a link you cited in another thread.
    import tests.basic.tables.ColorProvider;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.text.NumberFormat;
    public class DecoratedTablePrepareRenderer extends JFrame {
        JTable table;
        private DefaultTableModel model;
        public DecoratedTablePrepareRenderer() {
            Object[] columnNames = {"Type", "Company", "Price", "Shares", "Closed"};
            Object[][] data =
                        {"Buy", "IBM", new Double(80.50), new Double(1000), Boolean.TRUE},
                        {"Sell", "MicroSoft", new Double(6.25), new Double(2000), Boolean.FALSE},
                        {"Sell", "Apple", new Double(7.35), new Double(3000), Boolean.TRUE},
                        {"Buy", "Nortel", new Double(20.00), new Double(4000), Boolean.FALSE}
            model = new DefaultTableModel(data, columnNames);
            table = new JTable(model) {
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
                public Class getColumnClass(int column) {
                    return getValueAt(0, column).getClass();
                public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                    Component c = super.prepareRenderer(renderer, row, column);
                    if (isRowSelected(row))
                        c.setFont(c.getFont().deriveFont(Font.BOLD));
                    return c;
            ColorProvider prov = new TransactionColorProvider();
            ColorTableCellRenderer renderer = new ColorTableCellRenderer(table.getDefaultRenderer(Object.class),prov);
            ColorTableCellRenderer boolrenderer = new ColorTableCellRenderer(table.getDefaultRenderer(Boolean.class),prov);
            ColorTableCellRenderer doublerenderer = new ColorTableCellRenderer(table.getDefaultRenderer(Double.class),prov);
                    int priceIndex = model.findColumn("Price");
              table.getColumnModel().getColumn(priceIndex).setCellRenderer( new EtchedBorderTableCellRenderer(new ColorTableCellRenderer(new CurrencyRenderer(),prov) ));
            table.setDefaultRenderer(Object.class,new EtchedBorderTableCellRenderer(renderer));
            table.setDefaultRenderer(Double.class,new EtchedBorderTableCellRenderer(doublerenderer));
            table.setDefaultRenderer(Boolean.class, new EtchedBorderTableCellRenderer(boolrenderer));
            JScrollPane scrollPane = new JScrollPane(table);
            getContentPane().add(scrollPane);
        class CurrencyRenderer extends DefaultTableCellRenderer {
            private NumberFormat formatter;
            public CurrencyRenderer() {
                super();
                formatter = NumberFormat.getCurrencyInstance();
                setHorizontalAlignment(SwingConstants.RIGHT);
            public void setValue(Object value) {
                if ((value != null) && (value instanceof Number)) {
                    value = formatter.format(value);
                super.setValue(value);
        public static void main(String[] args) {
            DecoratedTablePrepareRenderer frame = new DecoratedTablePrepareRenderer();
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        class ColorTableCellRenderer implements TableCellRenderer{
            protected TableCellRenderer delegate;
            protected ColorProvider provider;
            public ColorTableCellRenderer(TableCellRenderer delegate, ColorProvider provider) {
                this.delegate = delegate;
                this.provider = provider;
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component c = delegate.getTableCellRendererComponent(table, value,isSelected,hasFocus,row, column);
                  c.setBackground(provider.getBackgroundColor(row, column));
                return c;
          class EtchedBorderTableCellRenderer implements TableCellRenderer{
            protected TableCellRenderer delegate;
            public EtchedBorderTableCellRenderer(TableCellRenderer delegate) {
                this.delegate = delegate;
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JComponent c = (JComponent)delegate.getTableCellRendererComponent(table, value,isSelected,hasFocus,row, column);
                  JPanel panel = new JPanel(new GridLayout(0,1));
                  panel.add(c);
                  panel.setBorder(BorderFactory.createEtchedBorder());
                return panel;
        class TransactionColorProvider implements ColorProvider {
            private int keyIndex = 0;
            private Color sellColor = Color.yellow;
            private Color buyColor = Color.green;
            public TransactionColorProvider() {
                keyIndex = model.findColumn("Type");
            public Color getBackgroundColor(int row, int column) {
                 if( model.getValueAt(row,keyIndex).equals("Sell")){
                     return sellColor;
                else {
                     return buyColor;
            public Color getForegroundColor(int row, int column) {
                return Color.black;
    }Boolean values are problematical since JCheckBox does seem to like borders, using a panel as I did in the Etched renderer seems to work. This solution need a little more work, this is submitted as a prototype
    Cheers
    DB

  • How to sum the  result rows at query designer

    Hi,
    We want to sum  the result rows which are at the end of the row by the help of query designer?So ,we directly see at analyzer
    exp:
       ..A.jan...A.feb...B.may...B.jun...SumA...SumB....SumA+B
    X..1............9..........6..............7........10.........13..........?????
    Edited by: zarata on Oct 23, 2011 12:49 PM
    Edited by: zarata on Oct 23, 2011 1:07 PM

    Hi,
    Could you please provide some more information.
    if you have characteristics iobject whose values are (A, B etc) and calendar month in rows and then at column level you have key figures then if you have turn on the "Display Result Rows" property of both iobject in Bex  as "Always" you can get the result. At the same time you can set "Display Overall result" property of the Query to get overall result.
    Regards,
    Pravin

Maybe you are looking for

  • Stuck on blue screen with clouds rainbow, floated ...

    As it says. When I start Skype, it goes straight to a blue screen with blue clouds and a green rainbow at the bottom. I get no prompt to login. I have followed various guides, such as renaming login to login1, deleting login, restarting the computer,

  • Is there a way to get this on here?

    I have Mac OS Leopard.. is there a way to get apple works on it.. I love apple works.

  • FR query ready export gives error

    Hi We are exporting a FR report in Query ready mode to Excel but its giving javascript error as Permission Denied. Any idea. Thanks

  • I kepp getting runtime errors

    I keep getting run time errrors.  I reinstall iTunes and now can even open it.  It comes up all the time in all my other applications now.  Happend since I tried to load the last update a couple of days ago.  What can I do?

  • Change IP-number and Subnet-mask with LabView?

    To upgrade the software on a CRio-System, the user needs to change some settings in the TCP/IP-configuration. To simplify this task I think on a possiblity to do (and at the end redo) the changes in the TCP/IP-Configuration of the Windows PC. What I