Better query

Hi Folks,
suppose
col1 col2
1 2
3 4
5 6
7 8
9 10
how can i able to get the output like
result
1
2
3
4
5
6
7
8
9
10
please suggest me.with my knowledge i wrote like this.
Is there any easy(logic) way rather than this, to simplify query lines???
select 1col1 from dual union all
select 3 from dual union all
select 5 from dual union all
select 7 from dual union all
select 9 from dual
,t2 as
(select 2 col2 from dual union all
select 4 from dual union all
select 6 from dual union all
select 8 from dual union all
select 10 from dual
,t3 as(
select col1 result from t1
union all
select col2 result from t2)
select result from t3 order by result
thanks alot in advance
Edited by: newbie on Feb 20, 2011 9:50 PM

SELECT RESULT FROM
select col1 result from (select 1 col1 from dual union all
select 3 from dual union all
select 5 from dual union all
select 7 from dual union all
select 9 from dual
UNION ALL
select col2 result from (select 2 col2 from dual union all
select 4 from dual union all
select 6 from dual union all
SELECT 8 FROM DUAL UNION ALL
SELECT 10 FROM DUAL))
ORDER BY RESULTEdited by: Mahir M. Quluzade on Feb 21, 2011 9:59 AM

Similar Messages

  • Write better query

    I am using oracle 10gR1 on windows.
    SELECT hr.msis, hs.mc, c.in_no
    FROM hr_num hr, SYS_no cx
    WHERE cx.msis=hr.msis And
    hr.mc<>'MN'
    How can i increase performance of this query.Plz sugest me or write better query?
    Thanks

    enable "autotrace on" at sql*plus and then execute that query and paste the plan as well as well statistics of this query here.Also paste the total number of rows for hr_num and SYS_no table and paste the result count for the table hr_num column mc.
    make sure is yours query predicate accurate
    And
    hr.mc'MN'
    Khurram

  • Help for efficient/better query

    DB Details:
    Oracle 11g R2 - 11.2.0.1
    CREATE TABLE workflow_routing_assoc
        wf_routing_assoc_id   NUMBER,                                 -- unique id
        routing_group_id      NUMBER,        -- common id for the four combination
        routing_rule_id       NUMBER, -- this column differnciates the information provided eg: date,day,month,year
        routing_rule_value    VARCHAR2 (50 BYTE), -- this column contains the information for the routing_rule_id(third column) eg: 01(date),wed(day),month(sep),year(2011)
        created_by            VARCHAR2 (50 BYTE),              --created user name
        created_date          timestamp (6),                        --created date
        modified_by           VARCHAR2 (50 BYTE),           -- modifying user name
        modified_date         timestamp (6)
    )                                                              --modified date
    INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                        routing_group_id,
                                        routing_rule_id,
                                        routing_rule_value)
      VALUES   (1,
                55,
                8,
                'test-example');
    INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                        routing_group_id,
                                        routing_rule_id,
                                        routing_rule_value)
      VALUES   (2,
                55,
                5,
                '12');
    INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                        routing_group_id,
                                        routing_rule_id,
                                        routing_rule_value)
      VALUES   (3,
                55,
                2,
                'sep');
    INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                        routing_group_id,
                                        routing_rule_id,
                                        routing_rule_value)
      VALUES   (4,
                55,
                9,
                '2010');
    COMMIT;
    -- NEED A BETTER QUERY INSTEAD OF THIS
    *SQL> SELECT   result0.routing_group_id*
      *2    FROM   (SELECT   routing_group_id, routing_rule_id*
      *3              FROM   workflow_routing_assoc*
      *4             WHERE   routing_rule_value = 'test-example') result0,*
      *5           (SELECT   routing_group_id, routing_rule_id*
      *6              FROM   workflow_routing_assoc*
      *7             WHERE   routing_rule_value = '12') result1,*
      *8           (SELECT   routing_group_id, routing_rule_id*
      *9              FROM   workflow_routing_assoc*
    *10             WHERE   routing_rule_value = 'sep') result2,*
    *11           (SELECT   routing_group_id, routing_rule_id*
    *12              FROM   workflow_routing_assoc*
    *13             WHERE   routing_rule_value = '2010') result3*
    *14   WHERE       result0.routing_rule_id = 8*
    *15           AND result1.routing_rule_id = 5*
    *16           AND result2.routing_rule_id = 2*
    *17           AND result3.routing_rule_id = 9*
    *18           AND result0.routing_group_id = result1.routing_group_id*
    *19           AND result1.routing_group_id = result2.routing_group_id*
    *20           AND result2.routing_group_id = result3.routing_group_id;*
    op:
    ROUTING_GROUP_ID
                  55Thanks in advance

    Hi,
    What's wrong with the solution in the other thread?
    Query simplification
    Point out where it's getting the wrong results, and explain how you get the right results in those places. Post some new sample data and results if necessary.

  • REST API and best bets / query rules

    Is there a bug in this?  I can not get best bet results regardless of the query string.  For example, the following (according to MSDN documentation) should process the query rules and return a best bet.  But it doesnt.  Am I doing something
    wrong in the query?  It only seems to return ordinary results.  Performing the same search via Sharepoint's UI returns the best bet at the top.
    $.ajax({
    url: "http://myserver/sites/mysite/_api/search/query/?processbestbets=true&enablequeryrules=true&querytext='" + searchText + "'",
    type: 'GET',
    headers: {
    "accept": "application/json; odata=verbose"
    success: myCallback,
    error: function(data) {
    alert(data.responseXML.text);

    Hi Scott,
    With EnableQueryRules and ProcessBestBets set to true in the search rest api, we can get the promoted results(best bets) in SharePoint 2013.
    I recommend to type the search rest api URL in the browser directly and then check if the best bets are displayed at the top of the search results.
    It will not displayed inside the table for normal results.
    Please also make sure that the query text matches the query rule condition.
    Thanks,
    Victoria
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • A better  query needed

    DELETE FROM ACCOUNT_ASCTN WHERE LIST_ID = 3999 AND
    ACCOUNT_ID IN (
    SELECT ACCOUNT_ID FROM ACCOUNT_ASCTN WHERE
    LIST_STATUS_CODE ='A'
    AND LIST_ID =3999 MINUS (SELECT ACCOUNT_ID FROM WORKLIST_ACNT ));
    as sometimes it takes around 40 minutes for a particular list id if there are too many records in the acount_asctn table.
    I tried with exists but its only making it better by a few seconds .

    Hi , I know NOT IN is not recommended. But there is no harm if you just checking the performance.
    Any way you can use this also:
    DELETE FROM ACCOUNT_ASCTN aa
    WHERE LIST_ID = 3999
    AND LIST_STATUS_CODE ='A'
    AND acccount_id NOT EXISTS (SELECT NULL FROM WORKLIST_ACNT wa
    WHERE aa.ACCOUNT_ASCTN=wa.ACCOUNT_ID );
    And if WORKLIST_ACNT has a lot of records and there is an index on ACCOUNT_ID you can try this approach also.
    DELETE FROM ACCOUNT_ASCTN aa
    WHERE LIST_ID = 3999
    AND LIST_STATUS_CODE ='A'
    AND (SELECT count(wa.account_id) FROM WORKLIST_ACNT wa
    WHERE aa.ACCOUNT_ASCTN=wa.ACCOUNT_ID ) = 0;
    Also check is there index for LIST_ID and LIST_CODE_STATUS on ACCOUNT_ASCTN table.
    Regards

  • Selecting better query from performance point of view.

    Hi friends,
    I have one situation which following example represents exactly.
    we have a table marks.
    Table Marks ( Student_No number,exam_code number, Mark_subject1 number, Mark_subject2 number, Mark_subject3 number).
    What I want is to prepare a table Results in following way.
    I need to insert one record for each student's each total Marks of each subject.
    Like
    Marks:
    Student_No...........Exam_code........Mark_subject1........Mark_subject2........Mark_subject3
    .........1.......................1.....................10.........................15..........................12
    .........1.......................2.....................15.........................15..........................10
    .........2.......................1.....................10.........................10..........................10
    .........2.......................2.....................17.........................17..........................10
    Then I want to populate results table with following data.
    Student...................Subject..............TotalMarks
    .....1.......................Subject1..................25
    .....1.......................Subject2..................30
    .....1.......................Subject3..................22
    .....2.......................Subject1..................27
    .....2.......................Subject2..................27
    .....2.......................Subject3..................20
    This needs to be done within one procedure.
    I can do it by two ways.
    1)
    insert into Results select student_no, 'Subject1',sum(Mark_Subject1) from marks group by student_no;
    insert into Results select student_no,'Subject2',sum(Mark_Subject2) from Marks group by student_no;
    insert into Results select student_no,'Subject2',sum(Mark_Subject3) from Marks group by student_no;
    2)
    For i in (select student_no,sum(mark_subject1) sub1, sum(mark_subject2) sub2, sum(mark_subject3) sub3 from marks)
    loop
    insert into Results values(i.student_no,'Subject1',i.sub1);
    insert into Results values(i.student_no,'Subject2',i.sub2);
    insert into Results values(i.student_no,'Subject3',i.sub3);
    end loop;
    If we use first way, 3 times the table will be accessed and will be processed (sorted) for "grouped by" and all the resultant data will be inserted.
    If we use second way, the marks table will be accessed and processed for group by for only once. But for each record of result set, 3 inserts will be done.
    I am confused about which would be better way provided the number of records in marks table is around 1,00,000.
    Please help me deciding the better way.
    Regards,
    Dipali..

    I would avoid cursor for loops if at all possible.

  • ROWTYPE to get better query ?

    Hello,
    I have two identical tables:
    PHOTOS_TEMP AND IMAGES_TEST
    (ID PK number ,
    content blob,
    filename varchar2 (200),
    mimetype varchar2 (200),
    filesize varchar2 (200),
    res_id FK number,
    watermarked varchar2 (1))I have CODE 1, I want to make it more effecient perhaps by using %ROWTYPE,
    So, I tried CODE 2, but it did not work. It tells, "Too many values .... CONTENT must be declared ...."
    Can you plesae tune Code 1 ??
    h1. CODE 1 is working fine
    DECLARE
    type source_col is table of blob index by pls_integer ;
    V_source source_col;
    type id_col is table of number index by pls_integer ;
    V_id id_col;
    type char_col is table of IMAGES_TEST.FILENAME%TYPE index by pls_integer ;
    V_filename char_col;
    V_mimetype char_col;
    begin
    select content,filename,mimetype,id bulk collect into
    V_source,v_filename,v_mimetype,v_id from photos_temp
    where  temp = :P700_TEMP_IMAGE   for update  ;
    for i in V_source.first .. V_source.last
    loop
    ORDSYS.ORDImage.process(V_source(i), 'fixedScale=800 500');
    end loop;
    forall i in V_source.first .. V_source.last
    insert into IMAGES_test
    (res_id ,CONTENT,filename,mimetype,filesize,watermarked)
    values
    (:P700_res_ID ,V_source(i),V_filename(i),V_mimetype(i),
    dbms_lob.getlength(V_source(i)), 'Y');
    COMMIT;
    EXCEPTION
       WHEN OTHERS THEN
       RAISE;
    END;h1. CODE 2 supposed to be more efficient, but not working ?
    DECLARE
    type new_row is table of IMAGES_TEST%rowtype index by pls_integer ;
    v_row new_row;
    begin
    -- This may collect more than one row
    select * bulk collect into
    v_row from photos_temp
    where  temp = :P700_TEMP_IMAGE   for update  ;
    for i in v_row.id.first .. v_row.id.last
    loop
    ORDSYS.ORDImage.process(v_row.content(i), 'fixedScale=800 500');
    end loop;
    forall i in v_row.id.first .. v_row.id.last
    insert into IMAGES_test
    (res_id ,CONTENT,filename,mimetype,filesize,watermarked)
    values
    (:P700_res_ID ,v_row.contnet(i),v_row.filename(i),v_row.mimetype(i),
    dbms_lob.getlength(v_row.content(i)), 'Y');
    COMMIT;
    EXCEPTION
       WHEN OTHERS THEN
       RAISE;
    END;Best Regards,
    Fateh
    Edited by: Fateh on Nov 26, 2012 5:22 AM

    hi,
    In your CODE 1
    select content,filename,mimetype,id bulk collect into
    V_source,v_filename,v_mimetype,v_id from photos_temp
    where  temp = :P700_TEMP_IMAGE   for update  ;
    -- temp is not a collumn name nor a variable name
    ...So I think that does not work.
    In code 2 you must use the index "( i)" on the table variable and not on the attribute. So:
    v_row.contnet(i) --THIS IS WRONG!
    v_row(i).contnet -- This is OK
    Also:
    v_row.id.first --THIS IS WRONG!
    v_row.first --This is OK
    Below is an working example:
    insert into photos_temp (id ,filename) values ( 1,'peter');
    insert into photos_temp (id ,filename) values ( 2,'Fateh');
    commit;
    DECLARE
    type new_row is table of IMAGES_TEST%rowtype index by pls_integer ;
    v_row new_row;
    begin
      select * bulk collect into
       v_row from photos_temp
      --where  temp = :P700_TEMP_IMAGE  
      for update  ;
      --for i in v_row.id.first .. v_row.id.last
      for i in v_row.first .. v_row.last
      loop
      DBMS_OUTPUT.PUT_LINE('Id: ' || v_row(i).id || ' filename: ' || v_row(i).filename);
      end loop;
    end;
    Result:
    Id: 1 filename: peter
    Id: 2 filename: FatehAnd in your case for code 2 simplyfied:
    DECLARE
    type new_row is table of IMAGES_TEST%rowtype index by pls_integer ;
    v_row new_row;
    begin
      select * bulk collect into
       v_row from photos_temp
      --where  temp = :P700_TEMP_IMAGE  
      for update  ;
      --forall i in v_row.id.first .. v_row.id.last
      forall i in v_row.first .. v_row.last
      insert into IMAGES_test
      (id ,filename)
      values
      (v_row(i).id, v_row(i).filename);
    end;
    select
      id
      ,filename
    from
      images_test;
    Result:
    ID FILENAME                                                                                                                                                                                              
    1 peter                                                                                                                                                                                                   
    2 Fateh                                                                                                                                                                                                    Whoever this works in:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE     11.2.0.1.0     Production"
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    I think in oracle 9 you must use seperate table variables and not one table variable of a scalar type.
    Regards,
    Peter

  • Better SQL Query for clients without boundaries?

    I've been using and modifying/experimenting with Chris Nackers' SQL query for missing boundaries (http://myitforum.com/myitforumwp/2011/12/07/sql-query-to-identify-missing-smsconfigmgr-boundaries/)
    below (changed to add aliases)--but this seems to mainly be showing us non-clients, as several computers that were indeed missing boundaries (using SCCM 2007 SP2 R3, and all our boundaries are protected, most are IP Range, a few IP Subnet, none AD Site) are
    not being listed, and everything in the listing has NULL SYS.Client0.
    Is there a better query to pinpoint this issue, or maybe using something (error code or log?) that would show computers that can't find a distribution point or some other evidence of not having a boundary?
    Thanks!
    SELECT DISTINCT SYS.Name0, SYS.Client0, IPA.IP_Addresses0, IPS.IP_Subnets0, SMSAS.SMS_Assigned_Sites0
    FROM dbo.v_R_System SYS
    LEFT OUTER JOIN dbo.v_RA_System_IPSubnets IPS ON SYS.ResourceID = IPS.ResourceID
    LEFT OUTER JOIN dbo.v_RA_System_IPAddresses IPA ON SYS.ResourceID = IPA.ResourceID
    LEFT OUTER JOIN dbo.v_RA_System_SMSAssignedSites SMSAS ON SYS.ResourceID = SMSAS.ResourceID
    LEFT OUTER JOIN dbo.v_RA_System_SystemOUName SOU ON SYS.ResourceID = SOU.ResourceID
    WHERE (SMSAS.SMS_Assigned_Sites0 IS NULL)
    AND (NOT (IPA.IP_Addresses0 IS NULL))
    AND (NOT (IPS.IP_Subnets0 IS NULL))
    AND SYS.Operating_System_Name_and0 LIKE 'microsoft%server%'
    ORDER BY IPS.IP_Subnets0, SYS.Name0

    I gotcha now... I think most people, myself included, rely on finding clients that are not assigned to determine if a boundary is missing. If you expect clients to not be assigned that's not going to work for you.
    WHERE (SMSAS.SMS_Assigned_Sites0
    IS NULL) 
    AND (NOT (IPA.IP_Addresses0
    IS NULL))
    AND (NOT
    (IPS.IP_Subnets0 IS
    NULL))
    = This is saying show me all clients not assigned but they do have an IP address and they do have a subnet discovered.
    In the case of CM12 it is actually possible for that not to work anyway because you can have separate boundaries for client assignment and content lookup.
    I am not aware of any query that can compare the IP address, AD Site and IP subnet from each client to what's configured in boundaries and find machines that do not fall into any boundary.
    John Marcum | http://myitforum.com/myitforumwp/author/johnmarcum/

  • Query takes long time on multiprovider

    Hi,
    When i execute a query on the multiprovider, it takes very long time. it doesnt show up the results also. It just keep processing. I have executed the report only for one day but still it doesnt show any result. But when i execute on the cube, it executes quickly and shows the result.
    Actually i added one more cube to the multiprovider and ten transported that multiprovider to QA and PRD. Transportation went on successfully. After this i am unalbe to execute the reports on that multiprovider. What might be the cause? your help is appreciated.
    Thanks
    Annie

    Hi Annie.......
    Checklist for the performance of a Query........from a DOc........
    1. If exclusions exist, make sure they exist in the global filter area. Try to remove exclusions by subtracting out inclusions.
    2. Use Constant Selection to ignore filters in order to move more filters to the global filter area. (Use ABAPer to test and validate that this ensures better code)
    3. Within structures, make sure the filter order exists with the highest level filter first.
    4. Check code for all exit variables used in a report.
    5. Move Time restrictions to a global filter whenever possible.
    6. Within structures, use user exit variables to calculate things like QTD, YTD. This should generate better code than using overlapping restrictions to achieve the same thing. (Use ABAPer to test and validate that this ensures better code).
    7. When queries are written on multiproviders, restrict to InfoProvider in global filter whenever possible. MultiProvider (MultiCube) queries require additional database table joins to read data compared to those queries against standard InfoCubes (InfoProviders), and you should therefore hardcode the infoprovider in the global filter whenever possible to eliminate this problem.
    8. Move all global calculated and restricted key figures to local as to analyze any filters that can be removed and moved to the global definition in a query. Then you can change the calculated key figure and go back to utilizing the global calculated key figure if desired
    9. If Alternative UOM solution is used, turn off query cache.
    10. Set read mode of query based on static or dynamic. Reading data during navigation minimizes the impact on the R/3 database and application server resources because only data that the user requires will be retrieved. For queries involving large hierarchies with many nodes, it would be wise to select Read data during navigation and when expanding the hierarchy option to avoid reading data for the hierarchy nodes that are not expanded. Reserve the Read all data mode for special queriesu2014for instance, when a majority of the users need a given query to slice and dice against all dimensions, or when the data is needed for data mining. This mode places heavy demand on database and memory resources and might impact other SAP BW processes and tasks.
    11. Turn off formatting and results rows to minimize Frontend time whenever possible.
    12. Check for nested hierarchies. Always a bad idea.
    13. If u201CDisplay as hierarchyu201D is being used, look for other options to remove it to increase performance.
    14. Use Constant Selection instead of SUMCT and SUMGT within formulas.
    15. Do review of order of restrictions in formulas. Do as many restrictions as you can before calculations. Try to avoid calculations before restrictions.
    16. Check Sequential vs Parallel read on Multiproviders.
    17. Turn off warning messages on queries.
    18. Check to see if performance improves by removing text display (Use ABAPer to test and validate that this ensures better code).
    19. Check to see where currency conversions are happening if they are used.
    20. Check aggregation and exception aggregation on calculated key figures. Before aggregation is generally slower and should not be used unless explicitly needed.
    21. Avoid Cell Editor use if at all possible.
    22. Make sure queries are regenerated in production using RSRT after changes to statistics, consistency changes, or aggregates.
    23. Within the free characteristics, filter on the least granular objects first and make sure those come first in the order.
    24. Leverage characteristics or navigational attributes rather than hierarchies. Using a hierarchy requires reading temporary hierarchy tables and creates additional overhead compared to characteristics and navigational attributes. Therefore, characteristics or navigational attributes result in significantly better query performance than hierarchies, especially as the size of the hierarchy (e.g., the number of nodes and levels) and the complexity of the selection criteria increase.
    25. If hierarchies are used, minimize the number of nodes to include in the query results. Including all nodes in the query results (even the ones that are not needed or blank) slows down the query processing. The u201Cnot assignedu201D nodes in the hierarchy should be filtered out, and you should use a variable to reduce the number of hierarchy nodes selected.
    Also check this.........Recommendations for Modeling MultiProviders
    http://help.sap.com/saphelp_nw70/helpdata/EN/43/5617d903f03e2be10000000a1553f6/frameset.htm
    Hope this helps......
    Regards,
    Debjani......

  • Open invoice customer ageing query

    I have set up a query to find a customer aging report - open ivoices. I just want to have open records... does anyone have a better query for this?
    SELECT     TOP (100) PERCENT dbo.OCRD.CardName, dbo.OCRD.Balance, (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 0 AND
                          30 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [0-30], (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE())
                          BETWEEN 31 AND 60 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [31-60], (CASE WHEN DATEDIFF(DD,
                          T0.REFDATE, GETDATE()) BETWEEN 61 AND 90 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [61-90],
                          (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) > 91 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [90+],
                          dbo.OCRD.CardType, T1.TransType, T1.TransCode, T1.LineMemo, T1.BaseRef, dbo.OCRD.CardCode, T1.BalDueDeb
    FROM         dbo.OJDT AS T0 INNER JOIN
                          dbo.JDT1 AS T1 ON T1.TransId = T0.TransId INNER JOIN
                          dbo.OCRD ON dbo.OCRD.CardCode = T1.ShortName
    WHERE     (dbo.OCRD.Balance >= 1) AND (dbo.OCRD.CardType = 'C') AND (T1.BalDueDeb > 0)
    ORDER BY dbo.OCRD.CardName
    Regards,
    knut

    Knut,
    Try this:
    SELECT T2.CardName, T2.Balance,
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 0 AND
    30 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '0-30',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 31 AND
    60 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '31-60',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 61 AND
    90 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '61-90',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) >90
    THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '90+',
    T1.TransType, T1.TransCode, T1.LineMemo, T1.BaseRef, T2.CardCode
    FROM dbo.OJDT T0
    INNER JOIN dbo.JDT1 T1 ON T1.TransId = T0.TransId
    INNER JOIN dbo.OCRD T2 ON T2.CardCode = T1.ShortName
    WHERE (T2.Balance >= 1) AND (T2.CardType = 'C') AND (T1.BalDueDeb != T1.BalDueCred)
    Thanks,
    Gordon

  • Changing the query on a view object

    I have a view object right now, based on an entity. It is the default view object, so that means the query in the view object is straight forward, it grabs all of the attributes from the table. And there is no WHERE clause.
    In reality I only want to show a finite set of rows from my table. Every time a record is changed/edited in this entity and committed, a new row in the database is created with the same information (I'm using CreateWithParams) except for a few columns.
    I actually don't really have update on this table, just creation of new rows. But to the user, I want it to 'look' like they are editing something in the table.
    Example:
    12, 11:32,Thompson, 60 (the user edits this information in an adf table, and a new row is created in the db)
    12, 11:55, Thompson, 75
    I have a timestamp (see above) field in the database that is used as part of my primary key, so that I know which record is the latest.
    When the VO query is run, I want the user to only see the latest row from the db.
    12, 11:55, Thompson, 75
    So...
    I went to my VO, and I changed the WHERE query to add this:
    where t1.TimeStamp = (Select MAX(t2.TimeStamp) FROM rcl.x t2 where t1.uid = t2.uid);
    Now, this isn't a mysql/sql question. There's actually a better query that I'd rather run, but the VO editor doesn't allow me to change the query itself....
    When I save the new WHERE to my VO, run my page again, I get the expected result (showing me only the latest records).
    However, when I try and sort on the table in which my data is displayed, I am now getting ORDER BY errors.
    I don't want my VO to be read-only sql based. I want to be able to update my table, so I have my VO running off of the entity.
    Why doesn't the VO allow me to change the query itself? (Like do a subquery, instead of having my where clause do the work)
    Why are order by errors being thrown when I sort on my adf table after changing the where clause in my view?
    Hopefully I wasn't too convoluted in the explanation of my problem..
    Thanks in advance,
    Joel

    HI Joe,
    Regarding your problem you can do one of the following tasks:
    1- easily to tuning on your view object, I mean in the tuning page of the view you can set that only return 1 record or 2-3 record fetch not all the record.
    in the order by you will order by the timestamp field and descending.
    2- you can order by the timestamp descending and in the where clause only set the rownum<2 (will return the last record) you can also set rownum<5 and get the 4 last record etc.
    3-editing the view query in the expert mode is not advised at all because of many consequences that you will face.
    4- maybe it is not bat that you add a readonly view for the table you mentioned and every time you unpdate the entity just re-execute the read-only view.( this method maybe is good maybe is not it depends on your business logic)
    Regards.
    Edited by: Amir Khanof on Sep 3, 2010 11:11 PM

  • Weird result of oracle query before and after function base index creation

    Hi All,
    Here is the unique situation we are facing after creating just an index.
    The query result before the index and the query result after the index do not match.
    This is very illogical situation. Shidhar and me have done lot of R&D, also tried to get lots info from Google but we couldn't decipher the reason for that.
    I am giving you all the details about the query, index and tables with following steps.
    Please let us know if anything is going wrong from our side or is it a bug at oracle level which is a rarest possibility but a possibility.
    Step 1 :- Create table
    create table TEMP_COMP
    ID VARCHAR2(10),
    GROUP_ID VARCHAR2(10),
    TRAN_DATE DATE,
    AMT_1 NUMBER,
    AMT_2 NUMBER,
    AMT_3 NUMBER
    Step 2 :- Insert Sample data
    set feedback off
    set define off
    prompt Deleting TEMP_COMP...
    delete from TEMP_COMP;
    commit;
    prompt Loading TEMP_COMP...
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('01', 'G01', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('02', 'G01', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('03', 'G01', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('04', 'G01', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('05', 'G01', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('06', 'G01', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('07', 'G01', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('08', 'G01', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('09', 'G01', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('10', 'G01', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('01', 'G01', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('02', 'G01', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('03', 'G01', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('04', 'G01', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('05', 'G01', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('06', 'G01', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('07', 'G01', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('08', 'G01', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('09', 'G01', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('10', 'G01', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('01', 'G02', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('02', 'G02', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('03', 'G02', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('04', 'G02', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('05', 'G02', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('06', 'G02', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('07', 'G02', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('08', 'G02', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('09', 'G02', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('10', 'G02', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('01', 'G03', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('02', 'G03', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('03', 'G03', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('04', 'G03', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('05', 'G03', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('06', 'G03', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('07', 'G03', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('08', 'G03', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('09', 'G03', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('10', 'G03', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
    insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
    values ('11', 'G01', to_date('03-03-2008', 'dd-mm-yyyy'), 100, 200, 300);
    commit;
    prompt 41 records loaded
    set feedback on
    set define on
    prompt Done.
    Step 3 :- Execute the query.
    SELECT GROUP_ID
    , SUM(LAST_YR_REV) as "Year_2007_Amt"
    , SUM(CURR_YR_REV) as "Year_2008_Amt"
    FROM (
    SELECT GROUP_ID,
    CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200701'AND'200712'THEN SUM(AMT_1) ELSE 0 END AS LAST_YR_REV ,
    CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200801'AND'200812'THEN SUM(AMT_1) ELSE 0 END AS CURR_YR_REV
    FROM TEMP_COMP t
    WHERE GROUP_ID ='G01'
    AND TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200601'AND'200912'
    GROUP BY GROUP_ID, TRAN_DATE
    GROUP BY GROUP_ID
    The result of above query
    GROUP_ID Year_2007_Amt Year_2008_Amt
    G01 30 180
    Step 4 : Create composite index
    create index GROUP_ID_TRAN_DATE_IDX on TEMP_COMP (GROUP_ID, TO_CHAR(TRAN_DATE,'YYYYMM'))
    Step 5 : Execute once again query from step 3.
    SELECT GROUP_ID
    , SUM(LAST_YR_REV) as "Year_2007_Amt"
    , SUM(CURR_YR_REV) as "Year_2008_Amt"
    FROM (
    SELECT GROUP_ID,
    CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200701'AND'200712'THEN SUM(AMT_1) ELSE 0 END AS LAST_YR_REV ,
    CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200801'AND'200812'THEN SUM(AMT_1) ELSE 0 END AS CURR_YR_REV
    FROM TEMP_COMP t
    WHERE GROUP_ID ='G01'
    AND TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200601'AND'200912'
    GROUP BY GROUP_ID, TRAN_DATE
    GROUP BY GROUP_ID
    The result of above query
    GROUP_ID Year_2007_Amt Year_2008_Amt
    G01 0 210
    Thanks
    Sunil

    I just wanted to make a comment. The predicates in both your queries are flawed I believe. You convert a date column to a character and then you say only pick the converted result between two sets of characters.
    TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200601'AND'200912'It should be coded like this for a proper date range comparison:
    TRAN_DATE BETWEEN TO_DATE('200601','YYYYMM') AND TO_DATE('200912','YYYYMM')That will eliminate the need for you to create FBI that you created. You should now be able to create a regular (B*Tree) index on the TRAN_DATE column.
    Also, now that we have the structure of your tables and sample data, what business question are you trying to answer? I think there is a better query that can be written if we know the requirements.
    Hope this helps!

  • Oracle Sql Query issue Running on Different DB Version

    Hello All,
    I have come into situation where we are pruning sql queries on different DB version of Oracle and have performance issue. Let me tell you in brief and i really appreciate for your prompt response as its very imperative stuff.
    I have a query which is running on a DB of version 7.3.4 and it takes around 30 mins where as the same query when run on 8i it takes 15sec., its a huge difference. I have run the statistics to analyze on 7.3 and its comparatively very high. Question here is, the sql query trys to select data from same schema table and 2 tables from another DB using DB link and 2 other tables from another DB using DB link.So,how can we optimize this stuff and achieve this run as same time as 8i DB in 7.3. Hope i am clear about my question, Eagerly waiting for your replies.
    Thanks in Advance.
    Message was edited by:
    Ram8

    Difficult to be sure without any more detailed information, but I suspect that O7 is in effect copying the remote tables to local temp space, then joining; 8i is factoring out a better query to send to the remote DBs, which does as much work as possible on the remote DB before shipping remaining rows back to local.
    You should be able to use EXPLAIN PLAN to identify what SQL is being shipped to the remote DB, If you can't (and it's been quite a while since I tried DB links or O7) then get the remote DBs to yourself, and set SQL_TRACE on for the remote instances. Execute the query and then examine the remote trace files, And don't forget to turn off the tracing when you're done.
    Of course it could just be that the CBO got better,,,
    HTH - if not, post your query and plans for the local db, and the remote queries.
    Regards Nigel

  • Query for outgoing payment

    Hi All,
             i need a report for the outgoing payment where i could display the account details, the doc remarks, row total and also the payment mode, whther by cash or by cheque. I have a query but i dont know how to get the mode of payment and also how to get the row total??
    SELECT T0.[DocNum], T0.[DocDate], T1.[AcctName], T1.[Descrip], T0.[CashAcct], T0.[CheckAcct] FROM OVPM T0  INNER JOIN VPM4 T1 ON T0.DocEntry = T1.DocNum WHERE T0.[DocDate]  = [%0]
    How do i get the row total and the mode of payment incorporated in the query? apart from the doc date, can i also get a selection criteria for the mode of payment as well?? Can anyone please suggest a better query??
    Thanks in advance,
    Joseph

    Try this one to start:
    SELECT T0.DocNum, T0.DocDate, T1.AcctName, T1.Descrip, T0.CashAcct, T0.CheckAcct, T0.DocTotal, CASE WHEN T0.CashSum > 0 THEN 'Cash' WHEN T0.CreditSum > 0 THEN 'CC' WHEN T0.TrsfrSum > 0 THEN 'WIRE' ELSE 'Check' END AS 'Mode'
    FROM dbo.OVPM T0
    LEFT JOIN dbo.VPM4 T1 ON T0.DocEntry = T1.DocNum
    WHERE T0.DocDate = [%0\] AND T0.JrnlMemo != 'Cancelled'
    Thanks,
    Gordon

  • Web template with different sections from same query

    Hi all.
    we have a query that display some characteristics for a single employ; we want to create a web template that display, in different analisys items (referred to same data provider), parts of query result.
    The query has only characteristics and no indexes.
    To explain better:
    Query result:
    Employ      1000
    B.U.           AAA
    City            Rome
    Level           A
    Web template:
    +------------------+                    +-----------------------+
    !    Employ 1000   !                    !    City    Rome       !
    +------------------+                    !    Level   A          !
                                            +-----------------------+      
            +--------------------+
            !  B.U.      AAA     !
            +--------------------+
    We should be able to write a web template like this using 3 different query but the question is: can we use the same query ? DATA_ROW_FROM / DATA_ROW_TO parameters don't work because only limits data rows but we have 1 only row!
    Thanks to all.
    Valter Casse
    AMS-BW
    SSC

    Have you considered creating and using query views?

Maybe you are looking for

  • FREE GOODS FROM CUSTOMER N VENDOR

    hi please give me some idea how free goods from customer and free goods from vendors are managed .please give me the process flow. thanks n regards rn  sap mm

  • Crossdomain with same domain names

    i am trying to load file into a container but i am getting this error * Security Sandbox Violation ***Connection to http://d2hitob8rnr1aj.cloudfront.net/img/ads/jivox/qualcomm_new_aug12_new.txt?clickTAG=htt p://ads.raaga.com/a.aspx&Task=Click halted

  • I deteled my numbers can i get them back

    i deleted my numbers can i get them back, had icloud on 2 devices and never know and deleted  from 1 devices and deleted them of my other device, cn i get my numbers back

  • 2G won't ring when using AOL radio

    Downloaded AOL radio on my 2G Iphone and if I'm listening to the radio the phone won't ring thru. I know u can't use both the edge and the phone at the same time but does it block incoming calls?

  • How to work with Fuji RAF files?

    I'm using an Fuji S2 and shoot RAF files. These are not supported in Aperture. Is there a quick workaround?