Count records in table where fields not used in Report

Hi
I was wondering if anyone could help me with a problem I have. I am new to Crystal Reports... I am using CR2008 and XSD as a datasource.
I have the following tables used in the report.
Programme Table          Risk Table          Control Table          Test Table
ID               ID               ID               ID
Name               ProgrammeID          RiskID               ControlID
Details               Description          Description          Description
Opinion               Notes               Notes               Notes
               Risk Recs Table          Control Recs Table     Test Rec Table
               ID               ID               ID     
               RiskID               ControlID          TestID
               Description          Description          Description
In the report that I have to design, I need to display the Notes from each of the Risk, Control and Test tables in hierarchical order and also display the notes when there are one or more recommendations attached to each Notes.
          Risk Notes     - Display only when risk rec count <> 0
          Control Notes     - Display only when control rec count <> 0
          Test Notes     - Display only when test rec count <> 0
So far I have designed the report as follows:
I have grouping around the Risk Notes, Control Notes and Test Notes as
     Group 1 - Group by ProgrammeID
     Group 2 - Group by RiskID
     Group 3 - Group by ControlID
     Group 4 - Group by TestID
(This is giving me the notes in the order that I want)
Since I want to know if each of the risk, control and test have got any recommendations, I created summary counts to get the recommendation count for Risk, Control and Tests. But I am not able to get the right count. Effectively, what I need to do is go through the Risk Recommendation table and count the recommendations that belong to that particular RiskID. If the count = 0 then I want to supress the Risk Notes (Group Header 2.)
Can anyone suggest how to get the count?
Thanks

Hi
I am using Distinct Count.
When there are no recommendations then the count always comes out as 1 and the count is correct for the first grouping. After that even if there are more than one recommendation, the count is always 1!
How do I reset a summary count?
I even tried writing a formula to do the count..
NumberVar riskCount;
WhilePrintingRecords;
riskCount := DistinctCount ({RiskRec.ID}, {Control.RiskID})
and another formula to reset this count, even then the count is still coming out incorrect. It brings a value 1 when there are no recommendations and the count is right for one set of grouping only.
I have just recently started using CR and havent quite mastered it yet!
Thanks...

Similar Messages

  • How feed many record in table component and not use append command again

    hi master
    How I feed Multiple records in table component and not use append and save command again and again
    Same as oracle grid
    I give many record and save one time
    Please give me idea how I add Multiple record and save one time not use append and save command again and again
    Thank�s
    aamir

    Hi!
    appendRow() method just add temporal row. For add them to DB commitChanges() method should be used. So you can use appendRow() method several times, fill every new row and only then use commitChanges() method. In this case all new rows will be added to DB per one time.
    Thanks,
    Roman.

  • Delete records from tableA which are not in tableB

    Table A contains milions of records which is the best way to delete records from tableA which are not in tableB
    delete from tableA where empno not in (select empno from tableb)
    or
    delete from tableA where empno not exists (select empno from tableb
    where b.empno=a.empno)
    any help

    Hi
    If you can do this, do with this:
    create table tableC
    as select a.*
    from tableA a,
    (select empno from tableA
    minus
    select empno from tableB) b
    where a.empno = b.empno;
    drop table tableA;
    rename table tableC to tableA;
    Ott Karesz
    http://www.trendo-kft.hu

  • Can't drag the currency key in local currency to the pool of fields not use

    Hi everyone,
    Hopefully you can enlighten me with this issue coz im trying to drag the currency key in local currency to the pool of fields not used (UCWB<Data Model<Data Basis<Data Model(TAB)) but nothing happened, i can't transfer it to the pool of fields not used.
    Note:I came with this decision(transferring the currency key in local currency to the pool of fields not used ) because SAP prompt me with this:
    The currency key in local currency is not required in the data basis. It is merely an implicit part of the data model
    I really dont have any idea why i can't drag it to the pool of filed not used, i tried to look for some sap notes but i can't find one.
    thanks in advance

    Hi Dan,
    Actually it is not really an error, i just would like to pattern the configuration of our newly upgraded BI server  to our BW server.
    In our BW server, the currency key in local currency is mapped to the pool of fields not used. I can't seem to do the same in the BI server because everytime I try to drag the currency key in local currency to the pool of fields not used, nothing happens, it isn't mapped.

  • SELECT * FROM table WHERE id NOT IN?  Help with statement.

    Hi,
    Two tables. Orders (orderID = PK) and Paid Orders (orderID =
    FK)
    I want to display a recordset of orders from the Orders table
    where the
    order ID doesn't appear in the Paid Orders table.
    I have tried something like this:
    SELECT *
    FROM dbo.tblOrders
    WHERE orderID NOT IN ( SELECT TOP 100 PERCENT
    tblPaidOrders.orderID FROM
    dbo.tblPaidOrders )
    ...no joy with that though. Would appreciate some guidance.
    Thank you.
    Regards
    Nath.

    Hi Nancy,
    Before I begin that, can I ask if there is an issue with the
    OR?
    I need it to be:
    (orderID IN (SELECT qryPaidOrders.orderID FROM qryPaidOrders)
    ORDER BY
    orderdate ASC) AND ((customerid = MMColParam1) OR (vanopID =
    MMColParam2))
    MMColParam1 is exactly the same as MMColParam but, for some
    reason
    unbeknowns to me, DW8.0.2 won't allow me to use it twice.
    That's neither
    here nor there though, as creating a 2nd variable
    (MMColParam2) solves that
    particular issue.
    Do I need additional ( ) anywhere considering it is an OR
    though?
    Thanks.
    nath.
    "Nancy *Adobe Community Expert*" <[email protected]>
    wrote in message
    news:[email protected]...
    >I would think so .. now that you have the core statement
    working .. try
    >adding the other portions. Put the main statement in ( )
    and add the
    >others. Like this:
    >
    > SELECT *
    > FROM dbo.qryOrders
    > WHERE (orderID IN (SELECT qryPaidOrders.orderID FROM
    qryPaidOrders)
    > ORDER BY orderdate ASC) AND (customerid = MMColParam1)
    AND (vanopID =
    > MMColParam2)
    >
    > See what that gives you and fiddle with those till you
    get what you want.
    >
    >
    > --
    > Nancy Gill
    > Adobe Community Expert
    > BLOG:
    http://www.dmxwishes.com/blog.asp
    > Author: Dreamweaver 8 e-book for the DMX Zone
    > Co-Author: Dreamweaver MX: Instant Troubleshooter
    (August, 2003)
    > Technical Editor: DMX 2004: The Complete Reference, DMX
    2004: A
    > Beginner's
    > Guide, Mastering Macromedia Contribute
    > Technical Reviewer: Dynamic Dreamweaver MX/DMX: Advanced
    PHP Web
    > Development
    >
    >
    >
    >
    > "tradmusic.com" <[email protected]> wrote
    in message
    > news:[email protected]...
    >> Hi,
    >>
    >> After a bit of twiddling, I changed the statement to
    this:
    >>
    >> SELECT *
    >> FROM dbo.qryOrders
    >> WHERE orderID IN (SELECT qryPaidOrders.orderID FROM
    qryPaidOrders)
    >> ORDER BY orderdate ASC
    >>
    >> ...and it displays only those records who appear in
    the Paid Orders
    >> table. If I change this to NOT IN, it displays only
    the orders in the
    >> Orders table.
    >>
    >> Ideal, but I need to apply the customerID and
    vanopID variables....is
    >> that possible within this one statement?
    >>
    >> Really appreciate the help,
    >> Regards
    >> Nath.
    >>
    >> "Nancy *Adobe Community Expert*"
    <[email protected]> wrote in message
    >> news:[email protected]...
    >>> You've added to it since the first post. Take
    out the customerID and
    >>> vanopID parts and try focusing on just the
    orderID part. Get that
    >>> working first.
    >>>
    >>> I would try seeing if you can select those
    orderID's that are IN the
    >>> subquery first .. that would see whether or not
    the problem is the NOT
    >>> .. which should work .. but let's see first
    whether the culprit is the
    >>> query structure or not. See if you can select
    the orderID's that are in
    >>> the paid orders table from the main query.
    >>>
    >>>
    >>> --
    >>> Nancy Gill
    >>> Adobe Community Expert
    >>> BLOG:
    http://www.dmxwishes.com/blog.asp
    >>> Author: Dreamweaver 8 e-book for the DMX Zone
    >>> Co-Author: Dreamweaver MX: Instant
    Troubleshooter (August, 2003)
    >>> Technical Editor: DMX 2004: The Complete
    Reference, DMX 2004: A
    >>> Beginner's
    >>> Guide, Mastering Macromedia Contribute
    >>> Technical Reviewer: Dynamic Dreamweaver MX/DMX:
    Advanced PHP Web
    >>> Development
    >>>
    >>>
    >>> "tradmusic.com"
    <[email protected]> wrote in message
    >>> news:[email protected]...
    >>>> Hi Nancy,
    >>>>
    >>>> Have just tried that, but it is still
    displaying records whose orderID
    >>>> is also in a record in the Paid Orders
    table?
    >>>>
    >>>> I've got:
    >>>>
    >>>> SELECT *
    >>>> FROM dbo.qryOrders
    >>>> WHERE customerID = MMColParam OR vanopID =
    MMColParam1 AND orderID NOT
    >>>> IN (SELECT qryPaidOrders.orderID FROM
    qryPaidOrders)
    >>>> ORDER BY orderdate ASC
    >>>>
    >>>> Hope you can help.
    >>>> Thanks. :o)
    >>>> Nath.
    >>>>
    >>>>
    >>>> "Nancy *Adobe Community Expert*"
    <[email protected]> wrote in message
    >>>> news:[email protected]...
    >>>>> Why couldn't your inner query just be
    SELECT orderID from
    >>>>> dbo.tblPaidOrders? Wouldn't the top 100%
    be all of them?
    >>>>>
    >>>>>
    >>>>> --
    >>>>> Nancy Gill
    >>>>> Adobe Community Expert
    >>>>> BLOG:
    http://www.dmxwishes.com/blog.asp
    >>>>> Author: Dreamweaver 8 e-book for the DMX
    Zone
    >>>>> Co-Author: Dreamweaver MX: Instant
    Troubleshooter (August, 2003)
    >>>>> Technical Editor: DMX 2004: The Complete
    Reference, DMX 2004: A
    >>>>> Beginner's
    >>>>> Guide, Mastering Macromedia Contribute
    >>>>> Technical Reviewer: Dynamic Dreamweaver
    MX/DMX: Advanced PHP Web
    >>>>> Development
    >>>>>
    >>>>>
    >>>>> "tradmusic.com"
    <[email protected]> wrote in message
    >>>>>
    news:[email protected]...
    >>>>>> Hi,
    >>>>>>
    >>>>>> Two tables. Orders (orderID = PK)
    and Paid Orders (orderID = FK)
    >>>>>> I want to display a recordset of
    orders from the Orders table where
    >>>>>> the order ID doesn't appear in the
    Paid Orders table.
    >>>>>>
    >>>>>> I have tried something like this:
    >>>>>>
    >>>>>> SELECT *
    >>>>>> FROM dbo.tblOrders
    >>>>>> WHERE orderID NOT IN ( SELECT TOP
    100 PERCENT tblPaidOrders.orderID
    >>>>>> FROM dbo.tblPaidOrders )
    >>>>>>
    >>>>>> ...no joy with that though. Would
    appreciate some guidance. Thank
    >>>>>> you.
    >>>>>>
    >>>>>> Regards
    >>>>>> Nath.
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >

  • Select data from table where field is initial

    I have table that has 10 million records.
    I want to select data from this table where certain date field is blank.
    *SELECT * FROM table*
    INTO TABLE internal table
    WHERE PSTNG_DATE = BLANK.
    Does anybody know how to select data from data base table when certain field is blank.
    I cont select all data once and delete which i dont want, the table is big, it will blow up app server.
    thanks in advance,
    Sachin
    Moderator: Pls do not lock the posting instead provide me the link, its disrespecting.

    Respect the forum rules and common sense, and you will be respected.
    "how to select data from a database table when the field is blank" is very basic, and basic questions will be locked, because they have been asked many times and you can find the answer yourself with a little effort. There is nothing disrespectful about it.
    Thread locked.
    Thomas

  • Identify tables which are not used in any access seq.

    Hi
    Need to identify those tables (A500 - A999) which are NOT used in any access sequence (table T682I).
    Not sure how to do this.
    Thanks for the help

    Hi Karen,
    if you don't want to use SE11 and see it on one glance, you could use the following coding:
    DATA: it_t682i TYPE TABLE OF t682i,
          wa_t682i TYPE t682i,
          it_missing TYPE TABLE OF t682i,
          wa_count TYPE kotabnr VALUE 499.
    SELECT * FROM t682i INTO TABLE it_t682i
                  WHERE kvewe = 'A'
                  AND  kotabnr BETWEEN 500 AND 999.
    DO.
      ADD 1 TO wa_count.
      READ TABLE it_t682i INTO wa_t682i
                 WITH KEY kotabnr = wa_count.
      IF sy-subrc <> 0.
        CLEAR wa_t682i.
        MOVE wa_count TO wa_t682i-kotabnr.
        APPEND wa_t682i TO it_missing.
      ENDIF.
      IF wa_count = 999.
        EXIT.
      ENDIF.
    ENDDO.
    BREAK 'your user'.
    The table it_missing is just a quicky solution, you could use a table with just one field or use write to print the result.
    Hope that helps!
    Regards
    Nicola

  • Select from table where field contains the first 3 character

    The value of the field contains leading zeros like 0000000123, 0000001123, 0000011123.
    Now we need to check the table for entries that contains the first three characters excluding the zeros.
    If we are looking for '123' then we should be retrieving 0000000123 and not 0000001123 or 0000011123.
    Is there a way to get that value in SQL statement with only the exact result?
    Thanks.

    P156550 wrote:>
    > We've tried to use LIKE in our SQL statements and filtered it but there are a bunch of data and we want to get the exact row to improve the performance.
    Hello Adjhan,
    Yes, you need not use LIKE.
    You can use CONVERSION EXIT. I see that the length of your data is CHAR10.
    So try to use the code i have suggested & revert back if any doubts.
    @Soumyaprakash:
    If read the original post carefully, the OP has said:
    If we are looking for '123' then we should be retrieving 0000000123 and not 0000001123 or 0000011123.
    So LIKE does not come into the picture.
    Good Luck,
    Suhas

  • How to Display multiple records in Table in VC without using BAPI.

    Hi All,
    I am working on Visual composer (NW2004s SP10). I am trying to display Poitems from BAPI_PO_GETDETAIL. I am creating my front end using VC. I have created one form and one Table where I want to display POItems. I am writing my logic of retrieving data from BAPI in CAF.I am connecting them in Guided procedures.When I run my process in Guided Procedures I am getting single row displayed in table. Can Anyone help me how to display multiple rows in table.
    Regards,
    Sheetal

    Hi Sheetal,
    if the BAPI returns a table, then you get multiple rows. From which system is the BAPI, so that I can check the BAPI to give you further information.
    Best Regards,
    marcel

  • How to obtain the table index in word use LabVIEW Report Generation Toolkit for Microsoft Office

    I created a word templete and it had several tables. When I use the "Word Edit Cell" function in LabVIEW Report Generation Toolkit for Microsoft Office, the function need "table index", and I didn't find any function to get or set the table index in word document. How can I achieve my attention to write value to specified table cell using the "Word Edit Cell" function?
    Thanks for reply!
    YangAfreet

    Hi yangafreet
    You do not need to get the table index for the word edit cell.vi from anywhere. LabVIEW will automatically index all the tables in the document. See the attatched vi for an example.
    Rich
    Attachments:
    Table Edit.vi ‏23 KB

  • Tables related fields to develope a report

    Hi All,
    I would like to know a table that can give me the following:
    1. Account Receipt date
    2. A/p invoice processing date
    3. payment release date by tresury
    4.Vendor name
    5. invoice numbers relating to that vendor.
    We want to prepare a report but I need to know the tables where we can find this information so that a program can be prepared for the same.
    kindly help on an urgent basis.

    Hi:
         All dates related data are stored in document header table BKPF...For vendor name use LFA1 and its invoices please use BSIK (OPEN INVOICES) and BSAK (Cleared Invoices).
    Regards

  • Can not use crystal reports 2008

    Hi All
    I m not able to use crystal reports on windows server. I can use it everyehere  bt not on the server i dnt know if the problem is bcoz it's a 64bit machine or not.
    We are using .Net application.
    Thanks in advance.
    Anita

    Hi Anita
    Crystal Reports 2008 doesnu2019t have 64 bit support or runtime hence you are getting the attached error.                                                                               
    To run the application with Crystal reports there are two workarounds:                                                                               
    1. Run the IIS under 32 bit mode so that your application will use 32 bit Crystal Reports runtimes.                                                                               
    For this please do the steps mentioned below:                                                                               
    1.When compiling the application in Visual Studio .NET 2008 you will need to force it to 32 bit mode.                              
    You can do this by right-clicking the project name in the Solution Explorer.                                                       
    2.For VB.NET                                                                               
    Click Compile, then Advanced Compile Options.  For the Target CPU drop down box, change it from "AnyCPU" to "x86" then click OK.   
    3.For C#.NET                                                                               
    Click Build and change the Platform Target option from "Any CPU" to "x86".                                                                               
    Now follow the steps mentioned in the Kbase article from below link:                                                               
      http://support.microsoft.com/kb/894435                                                                               
    You should then be able to run the application on a 64 bit OS without error.                                                                               
    The second workaround is                                                                               
    To change the references in your web application to CR 10.5 i.e. Crystal Reports basic for Visual Studio 2008. Crystal Reports 10.5 has the runtime for 64 bit machine.                                                                               
    For this:                                                                               
    1. Uninstall Crystal Reports 2008 from your machine.                                                                               
    2. Run the set up file for Visual Studio 2008 (from CD or the installation source that you use).                                                                               
    3. Click on Repair.                                                                               
    4. From the list of components select Crystal Reports 10.5 and click on Next.                                                                               
    5. After the repair is done you should be able to use the application using Crystal Reports.                                                                               
    Hope this helps!!
                                                                                    Regards,                                                                               
    Sourashree

  • Slow SQL output when table alias is NOT used in order by clause

    Hi guys,
    My query is based on Oracle 9208
    I have a table TAB1 with 68000 records with transaction_id as the primary key in this table (unique index).
    I have another TAB2 with the same number of records again with transaction_id in this table (foreign key to above).
    I have the below query that gets executed via an application:-
    SELECT TO_CHAR(V1.TRANSACTION_ID), V1.POLICY_ID, V1.REQUEST_TYPE
    FROM <VIEW> V1 WHERE V1.CERT_SERIAL_NUM=56192 AND
    (V1.AUTH_GROUP_ID=0 OR V1.AUTH_GROUP_ID=1) AND ROWNUM <= 3 ORDER
    BY TRANSACTION_ID ASC
    The above view V1 is created as below:-
    CREATE OR REPLACE FORCE VIEW "V1"
    ("TRANSACTION_ID",
    "PARENT_TRANSACTION_ID",
    "CA_DN_ID",
    "AUTH_GROUP_ID",
    "POLICY_ID",
    "REQUEST_TYPE",
    "REQUEST_STATUS",
    "EE_DN_HASH",
    "EE_DN",
    "EE_EMAIL_HASH",
    "EE_EMAIL",
    "KEY_USAGE",
    "SMART_CARD_SERIAL",
    "CERT_TYPE",
    "CERT_SERIAL_NUM",
    "CERT_INDEX",
    "RENEWAL_FLAG",
    "ARCHIVE_FLAG",
    "TIME_RECEIVED",
    "DOWNLOADED",
    "REQUEST_DATA",
    "ACTION",
    "STEP_NUM")
    AS
    SELECT
    T1.transaction_id,
    T1.parent_transaction_id,
    T1.ca_dn_id,
    V2.auth_group_id,
    V2.policy_id,
    T1.request_type,
    T1.request_status,
    T2.ee_dn_hash,
    T2.ee_dn,
    T2.ee_email_hash,
    T2.ee_email,
    T2.key_usage,
    T2.smart_card_serial,
    T2.cert_type,
    T2.cert_serial_num,
    T2.cert_index,
    T2.renewal_flag,
    T2.archive_flag,
    T1.time_received,
    T1.downloaded,
    T1.request_data,
    V2.action,
    V2.step_num
    FROM TAB1
    <ANOTHER VIEW> V2,
    TAB2 T1,
    TAB2 T2
    WHERE
    T1.transaction_id = T2.transaction_id
    AND
    V2.policy_id = T1.policy_id
    order by transaction_id;
    The query at the top runs within milliseconds if the VIEW is created as :-
    order by t2.transaction_id
    But without the alias "t2" in the order by, the query takes about 1 1/2 minutes
    Can you tell me why? I thought if you ordering by primary key (lesser number of values compared to foreign key values), the query should be faster..no?
    Thanks in advance

    Thanks for keeping up with this issue Hemant.
    Here are the plans for each case.
    I would be very interested in how you'd recognize which plan is the best and what are the derivatives.
    I don't much (or rather anything!) what is 'card' values, 'cost' values etc which I believe are used to decide the best plan of the lot.
    Thanks again
    Note TAB1 and TAB2 are from view definition posted initially
    1) Execution Plan for VIEW1 <<-- With ORDER BY" clause but no table ailas (order by transaction_id)
    SQL> EXPLAIN PLAN FOR SELECT TO_CHAR(QT.TRANSACTION_ID), QT.POLICY_ID, QT.REQUEST_TYPE
    2 FROM <VIEW1> QT WHERE QT.CERT_SERIAL_NUM=24293 AND
    3 (QT.AUTH_GROUP_ID=0 OR QT.AUTH_GROUP_ID=1) AND ROWNUM <= 3 ORDER
    4 BY TRANSACTION_ID ASC
    5 /
    Explained.
    Elapsed: 00:00:01.00
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 3 | 195 | 17 |
    |* 1 | COUNT STOPKEY | | | | |
    | 2 | VIEW | VIEW1 | 17 | 1105 | 17 |
    |* 3 | SORT ORDER BY STOPKEY | | 17 | 38573 | 17 |
    | 4 | NESTED LOOPS | | 17 | 38573 | 10 |
    | 5 | MERGE JOIN CARTESIAN | | 1 | 167 | 9 |
    | 6 | VIEW | VIEW2 | 1 | 52 | 8 |
    | 7 | SORT UNIQUE | | 1 | 156 | 8 |
    | 8 | NESTED LOOPS | | 1 | 156 | 6 |
    | 9 | NESTED LOOPS | | 1 | 143 | 6 |
    | 10 | NESTED LOOPS OUTER | | 1 | 117 | 5 |
    |* 11 | HASH JOIN | | 1 | 104 | 5 |
    | 12 | NESTED LOOPS | | 1 | 52 | 2 |
    |* 13 | TABLE ACCESS FULL | TAB3 | 1 | 39 | 2 |
    |* 14 | INDEX UNIQUE SCAN | (PK_TAB4) | 1 | 13 | |
    | 15 | TABLE ACCESS FULL | TAB5 | 82 | 4264 | 2 |
    | 16 | VIEW PUSHED PREDICATE | View3 | 1 | 13 | |
    | 17 | NESTED LOOPS | | 1 | 52 | 2 |
    | 18 | NESTED LOOPS | | 1 | 39 | 2 |
    |* 19 | INDEX UNIQUE SCAN | (PK_TAB6) | 1 | 13 | 1 |
    |* 20 | INDEX RANGE SCAN | (PK_TAB7) | 1 | 26 | 1 |
    |* 21 | INDEX UNIQUE SCAN | (PK_TAB8) | 1 | 13 | |
    | 22 | TABLE ACCESS BY INDEX ROWID| TAB9 | 3 | 78 | 1 |
    |* 23 | INDEX UNIQUE SCAN | (PK_TAB9) | 1 | | |
    |* 24 | INDEX UNIQUE SCAN | (PK_TAB10)| 1 | 13 | |
    | 25 | BUFFER SORT | | 1 | 115 | 9 |
    | 26 | TABLE ACCESS BY INDEX ROWID | TAB2 | 1 | 115 | 1 |
    |* 27 | INDEX RANGE SCAN | (TAB2_IDX2)| 1 | | |
    |* 28 | TABLE ACCESS BY INDEX ROWID | TAB1 | 12 | 25224 | 1 |
    |* 29 | INDEX UNIQUE SCAN | (PK_TAB1) | 1 | | |
    Predicate Information (identified by operation id):
    1 - filter(ROWNUM<=3)
    3 - filter(ROWNUM<=3)
    11 - access("TAB5"."PATH_ID"="TAB4"."PATH_ID")
    13 - filter("TAB3"."AUTH_GROUP_ID"<>(-1) AND ("TAB3"."AUTH_GROUP_ID"=0 OR "TAB3"."AUTH_GROUP_ID"=1))
    14 - access("TAB3"."PATH_ID"="TAB4"."PATH_ID")
    19 - access("TAB5"."DOMAIN_ID"="TAB6"."DOMAIN_ID")
    20 - access("TAB6"."DOMAIN_ID"="TAB7"."DOMAIN_ID")
    21 - access("TAB7"."RULE_ID"="TAB8"."RULE_ID")
    23 - access("TAB9"."POLICY_ID"="TAB5"."POLICY_ID")
    24 - access("TAB9"."ASSOCIATED_FORM_ID"="TAB10"."FORM_ID")
    27 - access("TAB2"."CERT_SERIAL_NUM"=24293)
    28 - filter("View2"."POLICY_ID"="TAB1"."POLICY_ID")
    29 - access("TAB1"."TRANSACTION_ID"="TAB2"."TRANSACTION_ID")
    Note: cpu costing is off
    54 rows selected.
    Elapsed: 00:00:01.81
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 COLLECTION ITERATOR (PICKLER FETCH) OF 'DISPLAY'
    Statistics
    39 recursive calls
    0 db block gets
    629 consistent gets
    0 physical reads
    104 redo size
    5169 bytes sent via SQL*Net to client
    405 bytes received via SQL*Net from client
    5 SQL*Net roundtrips to/from client
    31 sorts (memory)
    0 sorts (disk)
    54 rows processed
    2) Execution Plan for VIEW1 <<-- With ORDER BY" clause and table alias (order by TAB2.transaction_id)
    SQL> explain plan for SELECT TO_CHAR(QT.TRANSACTION_ID), QT.POLICY_ID, QT.REQUEST_TYPE
    2 FROM <VIEW1> QT WHERE QT.CERT_SERIAL_NUM=30003 AND
    3 (QT.AUTH_GROUP_ID=0 OR QT.AUTH_GROUP_ID=1) AND ROWNUM <= 3 ORDER
    4 BY TRANSACTION_ID ASC
    5 /
    Explained.
    Elapsed: 00:00:10.20
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 3 | 195 | 14 |
    | 1 | SORT ORDER BY | | 3 | 195 | 14 |
    |* 2 | COUNT STOPKEY | | | | |
    | 3 | VIEW | VIEW1 | 17 | 1105 | 13 |
    | 4 | NESTED LOOPS | | 17 | 38573 | 13 |
    | 5 | MERGE JOIN CARTESIAN | | 1 | 167 | 12 |
    |* 6 | TABLE ACCESS BY INDEX ROWID | TAB2 | 1 | 115 | 4 |
    | 7 | INDEX FULL SCAN | (TAB2_IDX) | 94 | | 1 |
    | 8 | BUFFER SORT | | 1 | 52 | 8 |
    | 9 | VIEW | VIEW2 | 1 | 52 | 8 |
    | 10 | SORT UNIQUE | | 1 | 156 | 8 |
    | 11 | NESTED LOOPS | | 1 | 156 | 6 |
    | 12 | NESTED LOOPS | | 1 | 143 | 6 |
    | 13 | NESTED LOOPS OUTER | | 1 | 117 | 5 |
    |* 14 | HASH JOIN | | 1 | 104 | 5 |
    | 15 | NESTED LOOPS | | 1 | 52 | 2 |
    |* 16 | TABLE ACCESS FULL | TAB3 | 1 | 39 | 2 |
    |* 17 | INDEX UNIQUE SCAN | (PK_TAB4) | 1 | 13 | |
    | 18 | TABLE ACCESS FULL | TAB5 | 82 | 4264 | 2 |
    | 19 | VIEW PUSHED PREDICATE | View3 | 1 | 13 | |
    | 20 | NESTED LOOPS | | 1 | 52 | 2 |
    | 21 | NESTED LOOPS | | 1 | 39 | 2 |
    |* 22 | INDEX UNIQUE SCAN | (PK_TAB6) | 1 | 13 | 1 |
    |* 23 | INDEX RANGE SCAN | (PK_TAB7) | 1 | 26 | 1 |
    |* 24 | INDEX UNIQUE SCAN | (PK_TAB8) | 1 | 13 | |
    | 25 | TABLE ACCESS BY INDEX ROWID| TAB9 | 3 | 78 | 1 |
    |* 26 | INDEX UNIQUE SCAN | (PK_TAB9) | 1 | | |
    |* 27 | INDEX UNIQUE SCAN | (PK_TAB10) | 1 | 13 | |
    |* 28 | TABLE ACCESS BY INDEX ROWID | TAB1 | 12 | 25224 | 1 |
    |* 29 | INDEX UNIQUE SCAN | (PK_TAB1) | 1 | | |
    Predicate Information (identified by operation id):
    2 - filter(ROWNUM<=3)
    6 - filter("TAB2"."CERT_SERIAL_NUM"=30003)
    14 - access("TAB5"."PATH_ID"="TAB4"."PATH_ID")
    16 - filter("TAB3"."AUTH_GROUP_ID"<>(-1) AND ("TAB3"."AUTH_GROUP_ID"=0 OR "TAB3"."AUTH_GROUP_ID"=1))
    17 - access("TAB3"."PATH_ID"="TAB4"."PATH_ID")
    22 - access("TAB5"."DOMAIN_ID"="TAB6"."DOMAIN_ID")
    23 - access("TAB6"."DOMAIN_ID"="TAB7"."DOMAIN_ID")
    24 - access("TAB7"."RULE_ID"="TAB8"."RULE_ID")
    26 - access("TAB9"."POLICY_ID"="TAB5"."POLICY_ID")
    27 - access("TAB9"."ASSOCIATED_FORM_ID"="TAB10"."FORM_ID")
    28 - filter("VIEW2"."POLICY_ID"="TAB1"."POLICY_ID")
    29 - access("TAB1"."TRANSACTION_ID"="TAB2"."TRANSACTION_ID")
    Note: cpu costing is off
    53 rows selected.
    Elapsed: 00:00:08.29
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 COLLECTION ITERATOR (PICKLER FETCH) OF 'DISPLAY'
    Statistics
    1079 recursive calls
    0 db block gets
    597 consistent gets
    21 physical reads
    0 redo size
    5177 bytes sent via SQL*Net to client
    405 bytes received via SQL*Net from client
    5 SQL*Net roundtrips to/from client
    63 sorts (memory)
    0 sorts (disk)
    53 rows processed
    3) Execution Plan for VIEW1 <<-- Without any "ORDER BY" clause
    SQL> explain plan for SELECT TO_CHAR(QT.TRANSACTION_ID), QT.POLICY_ID, QT.REQUEST_TYPE
    2 FROM <VIEW1> QT WHERE QT.CERT_SERIAL_NUM=30003 AND
    3 (QT.AUTH_GROUP_ID=0 OR QT.AUTH_GROUP_ID=1) AND ROWNUM <= 3 ORDER
    4 BY TRANSACTION_ID ASC
    5 /
    Explained.
    Elapsed: 00:00:10.20
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 3 | 213 | 11 |
    | 1 | SORT ORDER BY | | 3 | 213 | 11 |
    |* 2 | COUNT STOPKEY | | | | |
    | 3 | NESTED LOOPS | | 17 | 1207 | 10 |
    | 4 | MERGE JOIN CARTESIAN | | 1 | 32 | 9 |
    | 5 | VIEW | VIEW2 | 1 | 26 | 8 |
    | 6 | SORT UNIQUE | | 1 | 156 | 8 |
    | 7 | NESTED LOOPS | | 1 | 156 | 6 |
    | 8 | NESTED LOOPS | | 1 | 143 | 6 |
    | 9 | NESTED LOOPS OUTER | | 1 | 117 | 5 |
    |* 10 | HASH JOIN | | 1 | 104 | 5 |
    | 11 | NESTED LOOPS | | 1 | 52 | 2 |
    |* 12 | TABLE ACCESS FULL | TAB3 | 1 | 39 | 2 |
    |* 13 | INDEX UNIQUE SCAN | PK_TAB4 | 1 | 13 | |
    | 14 | TABLE ACCESS FULL | TAB5 | 82 | 4264 | 2 |
    | 15 | VIEW PUSHED PREDICATE | VIEW3 | 1 | 13 | |
    | 16 | NESTED LOOPS | | 1 | 52 | 2 |
    | 17 | NESTED LOOPS | | 1 | 39 | 2 |
    |* 18 | INDEX UNIQUE SCAN | PK_TAB6 | 1 | 13 | 1 |
    |* 19 | INDEX RANGE SCAN | PK_TAB7 | 1 | 26 | 1 |
    |* 20 | INDEX UNIQUE SCAN | PK_TAB8 | 1 | 13 | |
    | 21 | TABLE ACCESS BY INDEX ROWID| TAB9 | 3 | 78 | 1 |
    |* 22 | INDEX UNIQUE SCAN | PK_TAB9 | 1 | | |
    |* 23 | INDEX UNIQUE SCAN | PK_TAB10 | 1 | 13 | |
    | 24 | BUFFER SORT | | 1 | 6 | 9 |
    | 25 | TABLE ACCESS BY INDEX ROWID | TAB2 | 1 | 6 | 1 |
    |* 26 | INDEX RANGE SCAN | TAB2_IDX2 | 1 | | |
    |* 27 | TABLE ACCESS BY INDEX ROWID | TAB1 | 12 | 468 | 1 |
    |* 28 | INDEX UNIQUE SCAN | PK_TAB1 | 1 | | |
    Predicate Information (identified by operation id):
    2 - filter(ROWNUM<=3)
    10 - access("TAB5"."PATH_ID"="TAB4"."PATH_ID")
    12 - filter("TAB3"."AUTH_GROUP_ID"<>(-1) AND ("TAB3"."AUTH_GROUP_ID"=0 OR "TAB3"."AUTH_GROUP_ID"=1))
    13 - access("TAB3"."PATH_ID"="TAB4"."PATH_ID")
    18 - access("TAB5"."DOMAIN_ID"="TAB6"."DOMAIN_ID")
    19 - access("TAB6"."DOMAIN_ID"="TAB7"."DOMAIN_ID")
    20 - access("TAB7"."RULE_ID"="TAB8"."RULE_ID")
    22 - access("TAB9"."POLICY_ID"="TAB5"."POLICY_ID")
    23 - access("TAB9"."ASSOCIATED_FORM_ID"="TAB10"."FORM_ID")
    26 - access("TAB2"."CERT_SERIAL_NUM"=1022)
    27 - filter("VIEW2"."POLICY_ID"="TAB1"."POLICY_ID")
    28 - access("TAB1"."TRANSACTION_ID"="TAB2"."TRANSACTION_ID")
    Note: cpu costing is off
    52 rows selected.
    Elapsed: 00:00:03.37
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 COLLECTION ITERATOR (PICKLER FETCH) OF 'DISPLAY'
    Statistics
    38 recursive calls
    0 db block gets
    287 consistent gets
    0 physical reads
    0 redo size
    5006 bytes sent via SQL*Net to client
    405 bytes received via SQL*Net from client
    5 SQL*Net roundtrips to/from client
    29 sorts (memory)
    0 sorts (disk)
    52 rows processed

  • How to count records in table and send email only if count 0

    I thought this would be fairly simple, but apparently not.  I'm trying to count the number of records I have in my staging table, and send an email if count > 0  . . . .  and . . . . I want to put the count in the body of the email. 
    I'm running into a problem with the concatenation part of it.
    SET NOCOUNT ON
    SELECT * FROM [dbo].[Staging]
    SELECT @@rowcount as Row_Count
    SET NOCOUNT OFF
    IF @@rowcount > 0
    BEGIN
    exec msdb.dbo.sp_send_dbmail @profile_name = 'MailTest',
    @recipients = '[email protected]',
    @subject = 'Successfully Loaded Production',
    @body = 'Successfully Loaded Production ' + @@rowcount + ' records loaded',
    @body_format = 'text'
    END
    The problem comes from the '+' character not being recognized.  Maybe it's out of scope, not sure.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Try this
    SET NOCOUNT ON
    IF EXISTS (SELECT TOP 1 1 FROM [dbo].[Staging])
    BEGIN
    exec msdb.dbo.sp_send_dbmail @profile_name = 'MailTest',
    @recipients = '[email protected]',
    @subject = 'Successfully Loaded Production',
    @body = 'Successfully Loaded Production ' + @@rowcount + ' records loaded',
    @body_format = 'text'
    END
    Thanks
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Count Records in Table Except If Related Record Exists in Child Table

    Dear All
    I have the following query that counts all of the records in the table SENAlert based upon the teacher's username in a related table.
    SELECT COUNT(SENAlert.SENAlertID) AS Expr1
    FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
    INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
    INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
    INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
    WHERE (Teacher.TeacherUsername = 'dsmith')
    I need to extend this query by adding another table called SENAlertHistory. I would like to count the number of alerts (SENAlertID) for the specified teacher
    but where there is no related record in the SENAlertHistory table. Here's what the relationship diagram looks like:
    What's going to happen is when a teacher clicks a button to say they have read an alert, I will record this in the SENAlertHistory table. Therefore when performing a count of how many unread alerts the teacher has, I need to ignore the alerts they have
    already read (i.e. the records in the SENAlertHistory table).
    This is a bit too advanced for me -- I have tried! I was hoping someone would be able to help me please?
    Many thanks
    Daniel

    Try below code
    -- If you dont need the read alert count
    SELECT COUNT(SENAlert.SENAlertID) AS Expr1
    FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
    INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
    INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
    INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
    WHERE (Teacher.TeacherUsername = 'dsmith')
    AND NOT EXISTS
    (SELECT * FROM SenAlertHistory SAH WHERE Teacher.TeacherCode = SAH.SenAlertHistoryTeacherCode and SENAlert.SENAlertID = SAH.SEMAlertHistorySENAlertID )
    -- If you need the read alert count
    SELECT COUNT(SENAlert.SENAlertID) - COUNT(SAH.SEMAlertHistorySENAlertID) AS Expr1,COUNT(SAH.SEMAlertHistorySENAlertID)readalert
    FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
    INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
    INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
    INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
    LEFT OUTER JOIN SenAlertHistory SAH ON Teacher.TeacherCode = SAH.SenAlertHistoryTeacherCode and SENAlert.SENAlertID = SAH.SEMAlertHistorySENAlertID
    WHERE (Teacher.TeacherUsername = 'dsmith')
    Thanks
    Saravana Kumar C

Maybe you are looking for

  • How do I get a list view? I can't stand the artwork view.

    Pertains to itunes and ipad

  • Creative Suite 5 and Acrobat 9 Pro Installation Question.

    Hi We currently have a number of machines that  have Acrobat 9 Pro installed as Standalone software along with Creative Suite 5, which is now showing up as two individual licenses, one for Acrobat 9 Pro and the other for Creative Suite Bundle. I have

  • Wrong character encoding from flash to mysql

    Hi, im experiencing problems with character encoding not functioning correctly when sending from flash to mysql. What i am doing is doing a contact form in flash which then sends the value to a php file which takes the values and inserts them into a

  • Burning CD for Solaris 10 x86

    am in the process if installing Solaris 10 on the Intel platfrom. I downloaded all 4 files sol-10-GA-x86-v[1-4]-iso.iso and burned them onto CDs. The first CD worked fine and most of the OS is installed. Then I got prompted for the second CD. when th

  • Webpages doesn't display

    Hello, I cannot visit one of my friend's website from my PC (IE/Chrome).However, I can visit from other PC or Smartphones. A message displays that "This webpages cannot display" However, I can visit other websites, I only cannot visit this website.Th