Creating a complex query in CR designer

I'm running Crystal Reports XI Release 2 on Windows NT. I have a very complex query and cannot figure out how to make it work in CR. Basically, I've got a table A with fields containing reference codes that may or may not be present. I created a SQL query that imbeds select statements in the select fields (the field names between SELECT and FROM). So, it would read something like SELECT field1, field2, (select Code_Name from REF_Table where REF_Table.code=TableA.code and TableA.code is not null) FROM TableA. That works great in SQL Developer.
In CR, I tried a command field but that produces a cartesian set where I get a line for every record that has the field for each and every record in TableA.  No good. I just want the name for the value in the TableA record translated to the name if it is present.  Is there a way to do this in CR? I used to be able to edit the SQL directly in CR but now it won't let me do that. Anyone know a better way to solve this kind of problem?

I'm not an Oracle guy so I don't know what you can or can't do in PL SQL.
I'm surprised that you are getting different results between SQL Developer and the CR Command. CR should pass the query, exactly as it's written back to the server, same as SQL Dev.
IN T-SQL...If  you want to make sure that the sub-query is returning only 1 row, try placing "TOP 1" behind the SELECT.
(select top 1 loc.location_name
from ref_location loc
where loc.location_num=obd.location_num and odb.location_num is not null)
I'm thinking that Oracle doesn't have the the TOP N option but it does have a rownum feature. So maybe...
(SELECT x.location_name
FROM (
    select loc.location_name
    from ref_location loc
    where loc.location_num=obd.location_num and odb.location_num is not null) x
WHERE rownum = 1
ORDER BY rownum)
This is assuming that Oracle allows you to use ORDER BY in a sub-query. T-SQL only allows it if it's used in conjunction with TOP N...
Just a thought,
Jason

Similar Messages

  • Complex QUERY with Variables

    I created a complex query to extract data from Journal entry and from Journal voucher. I post here a simplified version where I have deleted UDO references.
    I buit it in the Query analizer and it runs ok.
    I copied in SAP and it runs ok too.
    Now, I need to ask for the start date and end date, as in the first lines of script. But SAP raise an error message I dont understand. I tried to use '[%0]' and '[%1]' insthead of '2008/01/01' and '2008/02/29' 
    DECLARE @D1 DATETIME
    DECLARE @D2 DATETIME
    SET @D1='2008/01/01'
    SET @D2='2008/02/29'
    SELECT * FROM
    SELECT  
         A.ACCOUNT AS 'CO.GE ITALIA',
         OACT.ACCTNAME AS 'NOME CO.GE ITALIA',
         SUM(CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000' AND DEBIT<>0) THEN -DEBIT WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000')THEN 0 ELSE CREDIT END -
              CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000') THEN 0 WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000' AND CREDIT<>0)THEN -CREDIT ELSE DEBIT END) AS 'TOTALE'
    FROM (
    SELECT BTF1.* FROM BTF1
    UNION ALL
    SELECT JDT1.* FROM JDT1
    ) AS A
    LEFT JOIN OACT ON (OACT.ACCTCODE=A.ACCOUNT)
    LEFT JOIN OBTF ON (OBTF.BATCHNUM=A.BATCHNUM AND OBTF.TRANSID=A.TRANSID)
    WHERE A.REFDATE>=@D1 AND A.REFDATE<=@D2 AND (OBTF.BTFSTATUS<>'C' OR OBTF.BTFSTATUS IS NULL) AND (OACT.U_CUENTA<>'' AND OACT.U_CUENTA IS NOT NULL) AND (OACT.U_CUENTA<>'432000000')
    GROUP BY A.ACCOUNT, OACT.ACCTNAME
    UNION ALL
    SELECT  
         A.SHORTNAME AS 'CO.GE ITALIA',
         OCRD.CARDNAME AS 'NOME CO.GE ITALIA',
         SUM(CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000' AND DEBIT<>0) THEN -DEBIT WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000')THEN 0 ELSE CREDIT END -
              CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000') THEN 0 WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000' AND CREDIT<>0)THEN -CREDIT ELSE DEBIT END) AS 'TOTALE'
    FROM (
    SELECT BTF1.* FROM BTF1
    UNION ALL
    SELECT JDT1.* FROM JDT1
    ) AS A
    LEFT JOIN OACT ON (OACT.ACCTCODE=A.ACCOUNT)
    LEFT JOIN OBTF ON (OBTF.BATCHNUM=A.BATCHNUM AND OBTF.TRANSID=A.TRANSID)
    LEFT JOIN OCRD ON (OCRD.CARDCODE=A.SHORTNAME)
    WHERE A.REFDATE>=@D1 AND A.REFDATE<=@D2 AND (OBTF.BTFSTATUS<>'C' OR OBTF.BTFSTATUS IS NULL) AND (OACT.U_CUENTA<>'' AND OACT.U_CUENTA IS NOT NULL) AND (OACT.U_CUENTA='432000000')
    GROUP BY A.SHORTNAME, OCRD.CARDNAME
    ) AS B

    Thank you to everybody for your answers.
    I need to know more about this way to declare a variable in SAP.
    This is my question:
    If I need to filter by date a result from a Union All select, is sufficent to declare the Date Variable for one of the two tables in the Union All?
    Following a simple code to explain my dubt:
    DECLARE @D1 DATETIME
    DECLARE @D2 DATETIME
    SET @D1='2008/01/01'
    SET @D2='2008/02/29'
    SELECT A.ACCOUNT, A.DEBIT, A.CREDIT FROM
    SELECT * FROM JDT1
    UNION ALL
    SELECT * FROM BTF1
    ) AS A
    WHERE A.REFDATE>=@D1 AND A.REFDATE<=@D2
    Do you think the WHERE statment will continue to run as well for the Union All in the script main too?
    This is the modified initial code:
    /*SELECT * FROM JDT1 T0*/
    DECLARE @D1 DATETIME
    DECLARE @D2 DATETIME
    /* WHERE */
    SET @D1=/* T0.REFDATE */ '[%0]'
    SET @D2=/* T0.REFDATE */ '[%1]'
    Thanks in advance,
    Jonny Cortonicchi

  • How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?

    1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
    When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed  in the stat plan  ?
    2. Does rowsource statistics gives some kind of  understanding of Extended stats ?

    You can get Row Source Statistics only *after* the SQL has been executed.  An Explain Plan midway cannot give you row source statistics.
    To get row source statistics either set STATISTICS_LEVEL='ALL'  in the session that executes theSQL OR use the Hint "gather_plan_statistics"  in the SQL being executed.
    Then use dbms_xplan.display_cursor
    Hemant K Chitale

  • Complex query design suggestions

    Hi, I should first of all point out I'm new to pl/sql and struggling a bit so any help you can provide is really appreciated.
    I have the requirements for a complex query the conditions of which are as follows
    Four tables involved
    ProductGroups, Products, Stock, StockMovements
    Query requirements psudeocode (broken into bits to make things easier)
    /* CODE */
    Select distinct products
    where productgroup.group between 'a' and 'z'
    And stock.location = 'x'
    And stock.qty > 0
    For each product
         _myDate = currentdate - 1 year
         stkMvt= Select * from StockMovements where product = product
         If(select count(*) from stkMvt where code = 'A' and type = 'A' and source = 'A' and stkMvt.date > _myDate) > 0)
              -- exclude row / move next product
         End If
         If (select count(*) from stkMvt where code = 'B' and type = 'B' and source = 'B' and stkMvt.date> _myDate) > 0)
              -- exclude row / move next product
         End If
         If (select count(*) from stkMvt where code = 'C' and type = 'C' and source = 'C' and Qty > 0 and stkMvt.date> _myDate) > 0)
              -- exclude row / move next product
         End If
         If (select max(stkMvt.date) from stkMvt where code = 'D' and type = 'D' and source = 'D' < _myDate)
              If ( select max(stkMvt.date) from stkMvt where ((code = 'E' and type = 'E' and source 'E')
                   Or (code = 'F' and type = 'F' and source = 'F')
                   Or (code = 'G' and type = 'G' and source = 'G')) > _myDate )
                   -- exclude row / move next product
              End If
         End If
         -- Get the fields to return
         Qty1 = Select coalesce(sum(qty),0) from stkMvt where code = 'H' and type = 'H' and source = 'H'
         Qty2 = Select coalesce(sum(qty),0) from stkMvt where code = 'I' and type = 'I' and source = 'I'
         Qty3 = Select coalesce(sum(qty),0) from stkMvt where code = 'J' and type = 'J' and source = 'J' and stkMvt.date between :fromDate and :toDate
         LastDate = Select max(stkMvt.Date) from stkMvt
         StkQty = Select Qty from Stock where product = product
         AllQty = Select AllQty from Stock where product = product
         FreeQty = StkQty - AllQty
         Value = Select value from Stock
         Select group, product , Qty1, Qty2, Qty3, LastDate, StkQty, AllQty, FreeQty, Value INTO table/cursor
    Loop
    Return table / cursor
    /* CODE END */
    Any guidance about the best way to achieve the above in an SP or Package would be massively helpful,
    Thanks in advance
    Scott.

    Agreed, it is a mess and I was looking the other way when it was dumped into my lap to deal with unfortunately. Any pointers in the right direction would really be helping me out.
    ok first the table structures, I'll include only the relevant fields to make things a bit easier.
    CREATE TABLE "TEST"."CMGROUP"
    (     "CMGRP_GROUP" CHAR(4 BYTE),
         "CMGRP_DESC" CHAR(30 BYTE)
    CREATE TABLE "TEST"."CMPROD"
    (     "CMP_PRODUCT" CHAR(20 BYTE),
         "CMP_DESC" CHAR(50 BYTE),
         "CMP_GROUP" CHAR(4 BYTE),
         "CMP_SPECIAL" CHAR(1 BYTE)
    CREATE TABLE "TEST"."STOCK"
         "STK_PRODUCT" CHAR(20 BYTE),
         "STK_LOC" CHAR(5 BYTE),
         "STK_STKQTY" NUMBER,
         "STK_VALUE" NUMBER,
         "STK_ALLSTK" NUMBER
    CREATE TABLE "TEST"."STMOVE"
         "STMOV_LOC" CHAR(5 BYTE),
         "STMOV_PRODUCT" CHAR(20 BYTE),
         "STMOV_DATE" DATE,
         "STMOV_TYPE" CHAR(1 BYTE),
         "STMOV_SOURCE" CHAR(1 BYTE),
         "STMOV_CODE" CHAR(1 BYTE),
         "STMOV_QTY" NUMBER,
         "STMOV_YEAR" NUMBER(5,0),
         "STMOV_PERIOD" NUMBER(5,0)
    Relationships are as follows
    CMGROUP.CMGRP = CMPROD.CMP_GROUP (One to Many)
    CMPROD.CMP_PRODUCT = STOCK.STK_PRODUCT (One to Many)
    STOCK.STK_LOC = STMOVE.STMOV_LOC (Many to Many)
    STOCK.STK_PRODUCT = STMOVE.STMOV_PRODUCT (Many to Many)
    As for the requirements well they aren't straightforward but the gist of it is to return a ref cursor to a crystal report from an oracle package. The ref cursor is to contain the following
    select products that are
    1) In stock
    2) For a specific location
    3) In a range of product groups
    4) That either have a manual stock receipt movement within the last 12 months
    5) Or do not have the following stock movement within the last 12 months
         a. PO Receipt
         b. WO Receipt
         c. Stock Acquisition Receipt
    Of the results I need to
         1) Display the group
         2) Display the product
         3) Sum the Qty of WO Receipts from the 1st of the month (13 Months Ago) until today
         4) Sum the Qty of PO Receipts from the 1st of the month (13 Months Ago) until today
         5) Sum the Qty of Stock Transfers from the 1st of the month (13 Months Ago) until today
         6) Display the most recent stock movement date
         7) Display the current stock quantity
         8) Display the allocated stock quantity
         9) Display the available stock quantity
         10) Display the stock value
    Movement code definitions as follows     
    Manual Stock Receipt
    Stmov_type: O
    Stmov_source: J
    Stmov_code: G
    Purchase Order Goods Receipt
    Stmov_type: O
    Stmov_source: R
    Stmov_code: S
    Stock Requisition Receipt (Positive stmov_qty value)
    Stmov_type: G
    Stmov_source: J
    Stmov_code: L
    Stock Requisition Issue (Negative stmov_qty value)
    Stmov_type: G
    Stmov_source: J
    Stmov_code: L
    Manual Stock Issue to GL Account (Issue to workshop)
    Stmov_type: F
    Stmov_source: J
    Stmov_code: G
    Works order issue
    Stmov_type: F
    Stmov_source: W
    Stmov_code: G
    Works order receipt
    Stmov_type: 1
    Stmov_source: W
    Stmov_code: G
    There are a few other conditions and requirements but I think that covers the basics. If there is anything I've left out let me know and I do my best to provide.
    Thanks in advance
    Scott.

  • How to Create a Functiona Query

    Dear all,
    Could any body detail me how to create a functional query. Please give me step by step procedure to create a query.
    I would appreciate if you can give me a material with screen shots. Your help will be highly appreciated.
    Thank you
    Raghu Ram

    Hi Raghu,
               Go through this document it may help you,
    SAP Query
    Step 1: Create User Group – SQ03
    Follow the menu path – SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > User Groups
    a) In the User Group: Initial Screen -
    Enter User Group Code (self named)
    Click on “Create”
    b) In the User Group (Code): Create or Change pop-up window -
    Enter the User Group Description
    Click on “Save”
    c) In the Create Object Directory Entry pop-up window -
    Ö Click on “Local Object” button
    Ö The User Group Created is saved
    Step 2: Create User Group – SQ02
    Follow the menu path – SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > Infosets
    a) In the Infoset: Initial screen -
    Ö Enter Infoset Code (self named)
    Ö Click on “Create” button
    b) In the Infoset: Title & Database Screen -
    Ö Enter Description of Infoset in the “Name” field
    Ö In the Data Source selection: Select appropriate Data Source by clicking
    the radio button
    · Source the data can either be multiple tables OR single table. There are 4
    options for the user to select from
    Ö Click on “Continue” (Enter)
    Ö Selected Table gets displayed in the Infoset : Initial Screen
    c) In the Infoset: Initial Screen -
    Ö Click on “Insert Table” button
    d) In the Add Table Screen -
    Ö Enter the Table Name that is to be inserted
    Ö Click “Continue” (Enter)
    e) In the Infoset: Initial Screen -
    Ö Click on “Back” button
    f) In the Field Group Defaults pop-up Screen -
    Ö Select Appropriate Field Group Option by clicking on the radio button
    · there are 3 options to select from. User can select Empty Field Group
    option and then select the data fields in the steps explained further.
    Alternatively, User can select an option which clubs all the data fields
    From all the tables selected
    Ö Click “Continue” (Enter)
    g) In the Change Infoset Screen -
    · the left side lists the Tables that the user has selected in step b, c & d
    · In the right side, system creates field groups, one for each table listed in the
    left part. Initially, the Field Groups are empty
    Ö In the Left Side, Click on the arror next to the table name and expand and
    display all the data fields in the table
    Ö Select a Data Field from the expanded Table view, which is to be added to
    the Field Group on the right.
    Ö Select a Field Group on the right side, in which Data Field selected above
    has to be added
    Ö Right click on the Data Field selected and click on “Add Field to Field Group”
    Ö The selected Data Field gets added to the selected Field Group, which is
    indicated by an arrow next to the Field Group.
    Ö Carry out the steps above to add the required Data Fields to the respective
    Field Groups
    Ö After transferring Data Fields to Field Groups click on “Generate” button
    h) In the Create Object Directory Entry Screen -
    Ö Click on “Logical Object” button to generate the infoset
    i) In the Change Infoset Screen -
    Ö Click on the “Back” button
    j) User is taken back to the “Infoset: Initial Screen” which displays the
    created Infoset record.
    Step 3: Assigning User Group to Infoset – SQ03
    Follow the menu path – SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > User Groups
    a) In the User Groups: Initial screen -
    Ö Enter the User Group for which Infoset is to be assigned
    Ö Click on “Assign Users & Infosets” button
    b) In the User Group: Assign Users Screen -
    Ö Click on “Assign Infosets” button
    c) In the next screen, select the Infoset, which needs to be attached to the
    User Group selected
    d) Click on the “Back” button
    Step 4: Creating Query – SQ00 & SQ01
    Follow the menu path – SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > Queries
    a) In the “Query from User Group: Initial Screen -
    Ö Click on “Other User Groups” button
    Ö In the pop-up screen, User Groups, select the User Group for which the
    Query has to created. The pop-up screen closes.
    Ö Enter the Query Code in the “Query” field
    Ö Click on “Create” button
    b) A pop-up screen “Restrict Value Range” shows the list of Infosets assigned to
    the User Group
    Ö Select the Infoset for which Query has to be created
    c) In the new screen Create Query: Title, Format -
    Ö Enter the Description of the Query in the “Title” field
    Ö Click on the “Next Screen” button
    d) In the Select Field Group” screen
    Ö Select the Field Groups from which Data Fields have to be selected for the
    Output
    Ö Click on the “Next Screen” button
    e) In the “Select Field” screen -
    Ö Select the Data Fields, which should appear in the output
    Ö Click on the “Next Screen” button
    f) In the Screen “Selection” -
    Ö Select the Data Fields for the selection criteria
    Ö Enter the sequence in which the selected fields would appear in the input
    screen of the query.
    Ö Define if the selection criteria should be Single Value or Multiple Value Range
    by clicking in the appropriate check boxes
    Ö Click on the “Basic List’ button
    g) In the screen “Query Layout Design” -
    Ö Select the Output Fields from the Data Fields section by clicking the
    appropriate check box
    Ö Change the sequence of Data Field columns if required
    Ö Click on the “Test” button to test the query created
    h) On the “Test Query” screen click “Continue”
    i) In the “Query” screen -
    Ö Enter the selection criteria
    Ö Click on “Execute” button
    j) Save the Query created
    Step 5: Running the Query – SQ00
    a) In the Query From User Group: Initial screen –
    b) Click on “Other User Groups” button to select the User Group
    c) In the pop-up screen “User Groups” select the User Group
    d) System lists all the queries created for the User Group
    e) Select the appropriate Query
    f) Click on “Execute” button
    g) User is taken to the Selection screen
    h) Enter the selection criteria and click on “Execute” button
    i) System runs the query and gives the output
    Regards,
    Murali.

  • Trouble creating a Netezza datasource from SharePoint Designer 2010 using OLEDB

    I am trying to create a data source in SharePoint Designer 2010 for connecting to a Netezza database via OLEDB.  If I choose the Microsoft .NET Data Provider for OLEDB and give it the server name, username, and password, I get the following connection
    error:
    Server Error: An error occurred while retrieving the list of Databases from nzprod-vip: The data retrieval service encounterd an error during connection to the data source. Contact the server administrator for more information.
    (The server administrator had no additional information.)
     If I use a custom connection string, specifying the Netezza OLEDB provider,  whose format looks like this (actual database and credentials omitted):
    Provider=NZOLEDB;Password=...;User ID=...;
    Data Source=...;Initial Catalog=...;
    Persist Security Info=True;Port=5480;Logging Level=0;Log Path=nzconnect.log; Optimize for ASCII=True;
    I get the following connection error:
    Server Error: An error occurred while retrieving the list of Databases from nzprod-vip: The Web server cannot connect to the specified data source because the query may contain errors, the data source may be unavailable or configured improperly, or you Web
    site is behind a proxy server or firewall.
    If your Web site is behind a proxy server or firewall, verify that your server administrator has configured the Data Retrieval Services HTTP proxy server setting for Microsoft SharePoint Foundation.
    (We are not behind a proxy server or firewall.)
    The NZOLEDB provider is loaded on the SharePoint server running the SharePoint Data Retrieval Service. I can successfully connect to the Netezza database if I login directly to the SharePoint server and run a Netezza database
    browser that connects via NZOLEDB using the same parameters that are in custom connection string I tried through SharePoint Designer.
    Our SharePoint server configuration has one server for the application services (including the Data Retrieval Service) and two other servers running just SharePoint web services.   (We actually loaded the NZOLEDB driver on all three servers for
    good measure, though we think the server running the Data Retrieval Service would be right one.)
    We do not think SharePoint privileges are a factor, since we had our SharePoint administrator try to connect while running with full access privileges.
    Any help will be much appreciated.

    Hi Ronald,
    i am not quite sure how the OLEDB connect to the netezza, as i heard they also have their own OLEDB, as you mentioned.
    but please have a check this link, perhaps it may help to set up OLEDB in sharepoint designer
    http://office.microsoft.com/en-us/sharepoint-designer-help/add-a-database-as-a-data-source-HA010355745.aspx
    perhaps this link may help you in some way:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/0e4b5e49-49ef-4e6b-9ab8-ac954ab8d0be/how-do-i-add-c-to-webpage-in-sharepoint-designer?forum=sharepointcustomizationlegacy
    http://social.technet.microsoft.com/Forums/en-US/9ac4a7af-6e3f-41d8-8b8e-14b707697e06/c-code-to-connect-netezza-using-oledb-provider?forum=sqlintegrationservices
    http://www.rafael-salas.com/2010/06/ssis-and-netezza-loading-data-using-ole.html#!/2010/06/ssis-and-netezza-loading-data-using-ole.html
    Regards,
    Aries
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • How to store data from a complex query and only fresh hourly or daily?

    We have a report which runs quite slow (1-2 minutes) because the query is quite complicate, so we would like to run this query daily only and store in a table so for those procedures that need to use this complex query as a subquery, can just join to this table directly to get results.
    However, I am not sure what kind of object I should use to store data for this complex query. Is data in global temp table only persist within transaction? I need something that can persist the data and be access by procedures.
    Any suggestions are welcome,
    Cheers

    Thank you for your reply. I looked at the materialized view earlier on, but have some difficulties to use it. So I have some questions here:
    1.The complex query is not a sum or aggregate functions, it just need to get data from different tables based on different conditions, in this case is it still appropriate to use meterialized view?
    2.If it is, I created one, but how to use it in my procedure? From the articles I read, it seems I can't just query from this view directly. So do I need to keep the complex query in my procedure and how the procedure will use the meterialized view instead?
    3. I also put the complex query in a normal view, then create a materialized view for this normal view (I expect the data from the complex query will be cache here), then in the procedure I just select * from my_NormalView, but it takes the same time to run even when I set the QUERY_REWRITE_ENABLED to true in the alter session. So I am not sure what else I need to do to make sure the procedure use the materialized view instead of the normal view. Can I query from the Materialized View directly?
    Below in the code I copied from one of the article to create the materialized view based on my normal view:
    CREATE MATERIALIZED VIEW HK3ControlDB.MW_RIRating
    PCTFREE 5 PCTUSED 60
    TABLESPACE "USERS"
    STORAGE (INITIAL 50K NEXT 50K)
    USING INDEX STORAGE (INITIAL 25K NEXT 25K)
    REFRESH START WITH ROUND(SYSDATE + 1) + 11/24
    NEXT NEXT_DAY(TRUNC(SYSDATE), 'MONDAY') + 15/24
    enable query rewrite
    AS SELECT * FROM HK3ControlDB.VW_RIRating;
    Cheers

  • Query in Template Designer

    Hello,
    I'm trying to create a word template in template designer for appointments (BUS2000126). I've created a web service in the web service tool. In the web service tool I found a query, Query for Activities [ BTQAct ], which seems useful. I have allowed all query attributes, but they don't appear in the XML Scheme when I create the word template. Is it possible to use queries this way? If so, what could I have done wrong?
    Kind regards,
    Johan Wigert

    Hello Robert,
    I followed your advice and I've found the information that I want to publish. I have one additional question about the date though. I'm now using the date in:
    Administrativeheaderoforder - Datesofheader - Alldates - element1 - TimestampTo
    This seems to give me the starting date of the appointment. I'm not too happy about the format as it is now YYYYMMDDHHMMSS. I would like to have it like YYYY-MM-DD. Do you know if that's possible?
    Kind regards,
    Johan Wigert

  • Complex query crashing database!

    Hi
    Our 10g database runs on Windows 2003 (with 32 GB RAM on server).
    Whenever a user is running a particular complex query, the database just crashes suddenly.
    In fact, it doesn't write anything in alert log file for any problem.
    The user starts the query, it runs for sometime, then suddenly database crashes!
    Only way to work there after is to restart the database.
    Although I asked the user to not to run that query again but it is generated by some application which may generate similar query again!
    So, how I can prevent database from crashing again?
    Will creating a resource profile to allocate finite resource help? Problem is since database crashes so suddenly, I can't find any info from log files!
    Thanx

    The database instance crashes. We have to start the ORACLE.EXE again to up the database.
    Here is last few lines of the alert.log
    Fri Feb 05 11:14:59 2010
    Setting recovery target incarnation to 1
    Fri Feb 05 11:14:59 2010
    Successful mount of redo thread 1, with mount id 1911309359
    Fri Feb 05 11:14:59 2010
    Database mounted in Exclusive Mode
    Completed: alter database mount exclusive
    Fri Feb 05 11:14:59 2010
    alter database open
    Fri Feb 05 11:15:00 2010
    Beginning crash recovery of 1 threads
    parallel recovery started with 7 processes
    Fri Feb 05 11:15:00 2010
    Started redo scan
    Fri Feb 05 11:15:00 2010
    Completed redo scan
    3886 redo blocks read, 276 data blocks need recovery
    Fri Feb 05 11:15:00 2010
    Started redo application at
    Thread 1: logseq 179837, block 3
    Fri Feb 05 11:15:00 2010
    Recovery of Online Redo Log: Thread 1 Group 6 Seq 179837 Reading mem 0
      Mem# 0 errs 0: F:\DB LOG FILES\ORADATA\REDO06.LOG
      Mem# 1 errs 0: F:\DB LOG FILES MULTIPLEXED\ORADATA\REDO06.LOG
    Fri Feb 05 11:15:00 2010
    Completed redo application
    Fri Feb 05 11:15:00 2010
    Completed crash recovery at
    Thread 1: logseq 179837, block 3889, scn 10584777673
    276 data blocks read, 276 data blocks written, 3886 redo blocks read
    Fri Feb 05 11:15:01 2010
    LGWR: STARTING ARCH PROCESSES
    ARC0 started with pid=21, OS id=5752
    Fri Feb 05 11:15:01 2010
    ARC0: Archival started
    ARC1: Archival started
    ARC1 started with pid=22, OS id=4548
    Fri Feb 05 11:15:02 2010
    LGWR: STARTING ARCH PROCESSES COMPLETE
    Thread 1 advanced to log sequence 179838
    Thread 1 opened at log sequence 179838
      Current log# 7 seq# 179838 mem# 0: F:\DB LOG FILES\ORADATA\REDO07.LOG
      Current log# 7 seq# 179838 mem# 1: F:\DB LOG FILES MULTIPLEXED\ORADATA\REDO07.LOG
    Successful open of redo thread 1
    Fri Feb 05 11:15:02 2010
    ARC1: STARTING ARCH PROCESSES
    Fri Feb 05 11:15:02 2010
    ARC0: Becoming the 'no FAL' ARCH
    ARC0: Becoming the 'no SRL' ARCH
    Fri Feb 05 11:15:02 2010
    SMON: enabling cache recovery
    Fri Feb 05 11:15:02 2010
    ARC2: Archival started
    ARC1: STARTING ARCH PROCESSES COMPLETE
    ARC2 started with pid=23, OS id=6120
    Fri Feb 05 11:15:02 2010
    Successfully onlined Undo Tablespace 1.
    Fri Feb 05 11:15:02 2010
    SMON: enabling tx recovery
    Fri Feb 05 11:15:02 2010
    Database Characterset is WE8MSWIN1252
    replication_dependency_tracking turned off (no async multimaster replication found)
    Starting background process QMNC
    QMNC started with pid=25, OS id=5312
    Fri Feb 05 11:15:03 2010
    Completed: alter database open
    Fri Feb 05 11:15:03 2010
    ARC1: Becoming the heartbeat ARCH
    Fri Feb 05 11:16:01 2010
    Shutting down archive processes
    Fri Feb 05 11:16:06 2010
    ARCH shutting down
    ARC2: Archival stopped

  • MVIEW & Complex query.

    Is it impossible at all to create a materialized view using a complex query (i.e. joins + union)?
    Thanks in advance
    Fabio

    Okay, childishness aside, it is possible to create materialized views using joins, unions and sub-queries. However, these sorts of complex materialized views have limited refresh options.
    Cheers, APC

  • Working with multiple results of a complex query

    Hi all!
    As I "advance" in learning PL/SQL with oracle, I now get stuck in handling multiple results of a complex query. As far as I know, I cannot use a cursor here, as there is no table where the cursor could point to.
    Here is the concept of what I want to do (pseudocode):
    foreach result in SELECT * FROM table_1, table_n WHERE key_1 = foreign_key_in_n;
        -- do someting with the resultHere is my attemt, that freezes the browser gui and throws an internal database error:
    declare
        type t_stock is record(
                baggage_id  baggage.baggage_id%type,
                section_id  sections.section_id%type,
                shelf_id    shelves.shelf_id%type
        v_stock t_stock;
        rcnt number(2);
    begin
    dbms_output.put_line(TO_CHAR(rcnt));
    loop
         SELECT COUNT(*) INTO rcnt FROM (
                   SELECT baggage.baggage_id, sections.section_id, shelves.shelf_id
                   FROM baggage, sections, shelves
                   WHERE baggage.baggage_id = sections.contained_baggage_id
                        AND shelves.is_connex_to_section_id = sections.section_id);
         IF rcnt <= 0 THEN
              exit;
         END IF;
         SELECT baggage.baggage_id, sections.section_id, shelves.shelf_id INTO v_stock
         FROM baggage, sections, shelves
         WHERE baggage.baggage_id = sections.contained_baggage_id
              AND shelves.is_connex_to_section_id = sections.section_id
              AND ROWNUM < 2;
         UPDATE sections SET contained_baggage_id = NULL WHERE section_id = v_stock.baggage_id;
         commit; -- do I need that?
    end loop;
    END;
    /So, is there a way to traverse a list of results from a complex query? Maybe without creating a temporary table (or is that the better way?).
    regards, Alex
    I reformatted the code
    pktm

    Ok, here are the details:
    The tables are used to model kind of a transport system. There are terminals connected with sections that may contain 1 piece of baggage. The baggage is moved by a procedure through a transport system. After each of these "moving steps", I check if the baggage is in front of the shelf it should be in.
    [To be honest, the give statement doesn't contain the info, in which shelf the baggage wil bee inserted. That was spared out because of the lack of a working piece of code :)]
    But: if we consider the fact, that a baggage is in front of such a shelf in the way, that it should be put in this shelf, then all this makes some sense.
    - move baggae through a transport system
    - see if you can put baggage into a shelf
    In order to "put baggage in a shelf", I need to remove it from the transport section. As the transport system is not normalized, I need to update the section where the baggage was in.
    Uhm... yes it's a task that doesn't make too much sense. It seems to be some kind of general spirit in university homework :)
    But: the FOR r IN (Statement) lloks good. I'll use that.
    And, the ROWNUM < 2 is used to limit the size of the result to 1, there is no need to have a specific ordering. It's just because - afaik - oracle doesn't have a limit clause. I would appreciate your help if you know a better way to do limit resultsets.
    best regards, Alex

  • How can I make this complex query?

    I don’t know how can I do this complex query...
    I have the tables Customers, Vehicles and Models. A customer can have 0-N Vehicles and a vehicle have 1 Model.
    Customers: ID_Customer (PK), Name, LastName...
    Vehicles: ID_Vehicle (PK), ID_Customer, ID_Model, date_sale
    Models: ID_Modelo (PK), Model_Name
    Then I need to know the buy average time (date_sale) between 2 models (ID_Model)
    For example I have these Vehicles:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    1................................123....................1.............21/05/2000
    2................................459....................3............ 16/08/2000
    3................................123....................2............ 28/06/2001
    4................................516....................1............ 09/09/2001
    5................................459....................4............ 18/10/2002
    6................................516....................2............ 20/12/2002
    If I want to know the buy average time (date_sale) between ID_Model 1 and ID_Model 2 it is. (403 + 467) / 2 = 435 days !!!
    * Customer 123 (model 1 to 2): 25/06/2001 – 21/05/2000 ==> 403 days
    * Customer 516 (model 1 to 2): 01/12/2002 – 01/05/2000 ==> 467 days.
    I need to do the query for all the combination models. For example If I have the Models 1, 2 and 3 I need to obtain:
    Source_Model.....Target_Model....Buy_Average_Time
    1......................................1....................... xxx days
    1......................................2....................... xxx days
    1......................................3....................... xxx days
    2......................................1....................... xxx days
    2......................................2....................... xxx days
    2......................................3....................... xxx days
    3......................................1....................... xxx days
    3......................................2....................... xxx days
    3......................................3....................... xxx days
    If it is necessary I could create a table with the fields Source_Model, Target_Model and Buy_Average_Time for accelerate the query time response.
    But how can I do this query??????????
    Thanks very much!!!

    Hi,
    Thanks for your reply but It is not correct for me because the Customer could have several vehicles in her life.
    If I make the query with my examples data it is OK
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    1................................123....................1.............21/05/2000
    2................................459....................3............ 16/08/2000
    3................................123....................2............ 28/06/2001
    4................................516....................1............ 09/09/2001
    5................................459....................4............ 18/10/2002
    6................................516....................2............ 20/12/2002
    select v1.id_model as source_model,
    v2.id_model as target_model,
    avg (v2.date_sale - v1.date_sale) || ' days' as buy_average_time
    from vehicles v1,
    vehicles v2
    where v1.id_customer = v2.id_customer
    and v2.date_sale > v1.date_sale
    group by v1.id_model, v2.id_model;
    I received:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2.....................................435 days
    ..............3................................4.....................................793 days
    But If I insert a new vehicle:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    7................................516....................3............ 16/08/2003
    And I execute the query now I receive:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2...........................435 days
    ..............1................................3...........................706 days
    ..............2................................3...........................239 days
    ..............3................................4...........................793 days
    It is NO correct because I don’t have the 1 (Source_model) to 3 (Target_model) combination in the Vehicles data!!! (I have 1 to 2 and 2 to 3 but NO 1 to 3!!!!).
    Then the query is not OK for me!
    Besides If I modify the Vehicle 7 data and put ID_Model = 2:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    7................................516....................2............ 16/08/2003
    I received:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2...........................525,33 days
    ..............2................................2...........................239 days
    ..............3................................4...........................793 days
    It is NO correct because the BUY_AVERAGE_TIME for 1 to 2 combination is 435 days (the same of the original query) because I aggregate only the combination 2 to 2 with the ID_VEHICLE 7
    Below I attach the examples scripts.
    Could you help me with this query, please?
    Thanks very much!
    CREATE TABLE VEHICLES
    ID_VEHICLE NUMBER(9),
    ID_CUSTOMER NUMBER(9),
    ID_MODEL NUMBER(9),
    DATE_SALE DATE
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    1, 123, 1, TO_Date( '05/21/2000 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    2, 459, 3, TO_Date( '08/16/2000 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    3, 123, 2, TO_Date( '06/28/2001 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    4, 516, 1, TO_Date( '09/09/2001 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    5, 459, 4, TO_Date( '10/18/2002 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    6, 516, 2, TO_Date( '12/20/2002 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    7, 516, 2, TO_Date( '08/16/2003 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    COMMIT;
    CREATE TABLE MODELS
    ID_MODELO NUMBER(9),
    MODEL_NAME VARCHAR2(25 BYTE)
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    1, 'MODEL 1');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    2, 'MODEL 2');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    3, 'MODEL 3');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    4, 'MODEL 4');
    COMMIT;
    CREATE TABLE CUSTOMERS
    ID_CUSTOMER NUMBER(9),
    NAME VARCHAR2(25 BYTE),
    LASTNAME VARCHAR2(25 BYTE)
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    123, 'Customer 123', 'A');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    459, 'Customer 459', 'B');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    516, 'Customer 516', 'C');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    318, 'Customer 318', 'D');
    COMMIT;

  • Is it possible to create input ready query with free characteristics ?

    Hi All,
    Is it possible to include characteristics restricted with variables in free charatceristics panel to make input ready query?
    I am trying to create input ready query with above practice but unable to make query as input ready.
    I have created input ready query on aggregation level. If I include characteristics restricted with variables in rows or filter then it is working fine. .ie. I am able to input entries at runtime of query.
    Kindly help me out to find the solution as I have to include characteristics in free characteristics panel.

    Hi Tilak,
    Thanks for reply.
    As per my knowledge, Every characteristics which is included at aggregation level should be included in either rows or filter level in query designer.
    But as per my business requirement I have to include the characteristics restricted with variables( in default values only) in free characteristics. But the problem is if I do so the query runs in display mode not in input mode.
    So kindly help me if you have any solution for above scenario.
    ---Shamkant

  • Unable to create report. Query produced too many results

    Hi All,
    Does someone knows how to avoid the message "Unable to create report. Query produced too many results" in Grid Report Type in PerformancePoint 2010. When the mdx query returns large amount of data, this message appears. Is there a way to get all
    the large amount in the grid anyway?
    I have set the data Source query time-out under Central Administration - Manager Service applications - PerformancePoint Service Application - PerformancePoint Service Application Settings at 3600 seconds.
    Here Event Viewer log error at the server:
    1. An exception occurred while running a report.  The following details may help you to diagnose the problem:
    Error Message: Unable to create report. Query produced too many results.
            <br>
            <br>
            Contact the administrator for more details.
    Dashboard Name:
    Dashboard Item name:
    Report Location: {3592a959-7c50-0d1d-9185-361d2bd5428b}
    Request Duration: 6,220.93 ms
    User: INTRANET\spsdshadmin
    Parameters:
    Exception Message: Unable to create report. Query produced too many results.
    Inner Exception Message:
    Stack Trace:    at Microsoft.PerformancePoint.Scorecards.Server.PmServer.ExecuteAnalyticReportWithParameters(RepositoryLocation analyticReportViewLocation, BIDataContainer biDataContainer)
       at Microsoft.PerformancePoint.Analytics.ServerRendering.OLAPBase.OlapViewBaseControl.ExtractReportViewData()
       at Microsoft.PerformancePoint.Analytics.ServerRendering.OLAPBase.OlapViewBaseControl.CreateRenderedView(StringBuilder sd)
       at Microsoft.PerformancePoint.Scorecards.ServerRendering.NavigableControl.RenderControl(HtmlTextWriter writer)
    PerformancePoint Services error code 20604.
    2. Unable to create report. Query produced too many results.
    Microsoft.PerformancePoint.Scorecards.BpmException: Unable to create report. Query produced too many results.
       at Microsoft.PerformancePoint.Scorecards.Server.Analytics.AnalyticQueryManager.ExecuteReport(AnalyticReportState reportState, DataSource dataSource)
       at Microsoft.PerformancePoint.Scorecards.Server.PmServer.ExecuteAnalyticReportBase(RepositoryLocation analyticReportViewLocation, BIDataContainer biDataContainer, String formattingDimensionName)
       at Microsoft.PerformancePoint.Scorecards.Server.PmServer.ExecuteAnalyticReportWithParameters(RepositoryLocation analyticReportViewLocation, BIDataContainer biDataContainer)
    PerformancePoint Services error code 20605.
    Thanks in advance for your help.

    Hello,
    I would like you to try the following to adjust your readerquotas.
    Change the values of the parameters listed below to a larger value. We recommend that you double the value and then run the query to check whether the issue is resolved. To do this, follow these steps:
    On the SharePoint 2010 server, open the Web.config file. The file is located in the following folder:
    \Program Files\Microsoft Office Servers\14.0\Web Services\PpsMonitoringServer\
    Locate and change the the below values from 8192 to 16384.
    Open the Client.config file. The file is located in the following folder:
    \Program Files\Microsoft Office Servers\14.0\WebClients\PpsMonitoringServer\
    Locate and change the below values from 8192 to 16384.
    After you have made the changes, restart Internet Information Services (IIS) on the SharePoint 2010 server.
    <readerQuotas
    maxStringContentLength="2147483647"
    maxNameTableCharCount="2147483647"
    maxBytesPerRead="2147483647"
    maxArrayLength="2147483647"
                  maxDepth="2147483647"
    />
    Thanks
    Heidi Tr - MSFT
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • How to create an ABAP Query with OR logical expression in the select-where

    Hi,
    In trying to create an ABAP query with parameters. So it will select data where fields are equal to the parameters entered. The default logical expression is SELECT.. WHERE... AND.. However I want to have an OR logical expression instead of AND.. how can I attain this??
    Please help me on this.. Points will be rewarded.
    Thanks a lot.
    Regards,
    Question Man

    Hi Bhupal, Shanthi, and Saipriya,
    Thanks for your replies. But that didn't answer my question.
    Bhupal,
    You cannot just replace AND with OR in an ABAP QUERY. ABAP QUERY is a self generated SAP code. You'll just declare the tables, input parameters and output fields to be displayed and it will create a SAP standard code. If you'll try to change the code and replace the AND with OR in the SAP standard code, the system will require you to enter access key/object key for that particular query.
    Shanthi,
    Yes, that is exactly what need to have. I need to retireve DATA whenever one of the conditions was satisfied.
    Saipriya,
    Like what I have said, this is a standard SAP code so we can't do your suggestion.
    I have already tried to insert a code in the ABAP query (there's a part there wherein you can have extra code) but that didn't work. Can anybody help me on this.
    Thanks a lot.
    Points will be rewarded.
    Regards,
    Question Man

Maybe you are looking for

  • Facetime on iphone and a mac can i use the same apple id

    i have a mac and iphone 4. I can receive facetime on my phone (email address) but not the mac. so i tried to change the facetime settings on my phone so that i receive facetime by phone number but it wont change. Im led to believe it email address fo

  • Itunes sync with iphone 5 problem

    It's making me crazy.. I am trying to sync my iphone 5 with itunes on Mac. Tried everything.. My mac says syncing, then it says finished but no songs or no video is synced. Looking at the tree, I see the playlist but it's grey. (so not synced) I had

  • Should I use Samsung RAPID?

    So Samsung has a feature exclusive to their EVO line of SSD's.  Right now here is my setup. EVO 120gb: OS, programs EVO 500gb: Source files PNY 250gb: cache, scratch, previews 3x TB in RAID 5: exports, project files. Given this article: AnandTech | S

  • HNSC and App store

    My UAT set up: WFE name: abc.sharepoint.com Non host header site at port 80: http://abc.sharepoint.com  IIS for this site: http with ip * For App store: Added https binding on port 80 with new ip and app store certificate Extended abc.sharepoint.com

  • White Point Presets?

    Hello all, I am using the trial version of Aperture2 and so far, I really like running a native pro image editor. I was using Lightroom (still am, mainly at the moment), and it has built in white point presets (daylight, shade, tungsten, etc). Does A