Query question, OINV, OCRD, CRD1

When I try to create a query with the 3 tables above when I add the CRD1 the invoice numbers begin to duplicate.  Is this a problem with the JOIN statements automatically created by the Generator?
Thanks, Jeff
SELECT * 
FROM OINV T0  INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode

hi,
Query will be
SELECT *
FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode and T2.AdresType = 'B'
Jeyakanthan

Similar Messages

  • Problem in Query with JOIN Function in OCRD CRD1 OCPR tables

    Hello Dear Forum Users,
    I want to make a query which shows me per business partner from OCRD - Addres; CRD1 - Delivery Address and from OCPR - Contactperson information
    Is it possible to show it in one row per Business Partner. Now I get (the classic problem) of several rows and a duplication of the contact persons per (delivery) address.
    My query is:
    SELECT T0.[CardCode], T0.[CardName], T1.[Address], T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_MobNr], T1.[U_OpenTijd], T1.[U_LosIns_1], T1.[U_LosIns_2],T2.[Title],  T2.[Name] as 'Voornaam', T2.[Address] as 'Achternaam', T2.[Position] as 'Functie', T2.[Tel1], T2.[Cellolar], T2.[E_MailL], T2.[BirthDate] FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
    Can you help me ?
    Jos Dielemans - Maastricht
    Edited by: J. Dielemans on Apr 29, 2011 4:28 PM
    Changed the query with Left Outer Join

    I have found the solution myself:
    By using the Union All function I could combine two queries. Here is the result:
    SELECT
    T0.[CardCode], T0.[CardName], T1.[Address] , T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_OpenTijd] , T1.[U_LosIns_1] , T1.[U_LosIns_2]'
    FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
    WHERE T0.[CardCode] >= 'D00000'
    Union all
    SELECT
    T0.[CardCode], T0.[CardName], T2.[Position], T2.[Tel1], T2.[Title],  T2.[Name], T2.[Address], T2.[Position], T2.[Tel1], T2.[Cellolar], T2.[E_MailL]
    FROM OCRD T0 LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
    WHERE T0.[CardCode] >= 'D00000'
    Order by 1
    Now i got the result I was looking for.

  • Query Help (OCRD/CRD1)

    Hi All,
    Can anyone provide some pointers/help with the following 2 queries we're trying to make:
    1. A query to show any Customer which has more than 1 ship-to address in BP Master Data. We have the below, but are not sure how to introduce the greater than 1 condition.
    SELECT T0.[CardCode], COUNT(T0.[AdresType]) FROM CRD1 T0 WHERE T0.[AdresType] = 'S' GROUP BY T0.[CardCode]
    2. Once we make sure we have at maximum 1 Ship-To address per BP, we want to retrieve the "Ship-To" address for a BP if it exists, and if not, the "Bill-To". Note, there is never more than 1 "Bill-To" address.
    SELECT T0.CardCode, T0.CardName, T1.Street, T1.Block, T1.ZipCode FROM OCRD T0 INNER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode WHERE
    T0.FrozenFor = 'n' AND T0.CardType = 'c' AND IF EXISTS "Ship-To" THEN ..... ELSE "Bill-To" ???
    Hope this makes sense?
    Thanks,
    Raj
    Edited by: Rajiv Agarwalla on Sep 23, 2010 11:10 AM

    Hi Istvan,
    Thank you for your reply. I manged to get the first query to work correctly, but not the second one. It doesn't seem to retrieve the "Bill-To" address for BPs that only have a "Bill-To" and no "Ship-To". Would you please be able to point out my error in amending your syntax?
    SELECT T0.CardCode, T0.CardName ,T1.Street, T1.Block, T1.ZipCode
    FROM OCRD T0 INNER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
    WHERE T1.AdresType ='S' AND T0.CardType = 'C'
    (The above bit gets the "Ship-To" address for BPs where it exists)
    or not exists(Select T1.Street, T1.Block, T1.ZipCode from  CRD1 T1
                     where T1.CardCode=T0.CardCode and T1.AdresType ='B' AND T0.CardType = 'C')
    (This bit should be getting the "Bill-To" for BPs where no "Ship-To" exists?)
    Thanks!
    Rajiv

  • Query question/error

    I have the following query that functions correctly:
    SELECT T0.[CardCode] as 'Cust. No.', T0.[CardName] as 'Cust. Name', T0.[DocNum] as Document, T0.[DocCur] as Currency, T1.Rate, T0.[DocDate],T1.[ActDelDate] as 'Delivery date', datepart(MM,T0.[DocDate]) as Month,datepart(yyyy,T0.[DocDate]) as Year, T1.TotalFrgn, T1.[SubCatNum] as 'BP Catalog',T1.[ItemCode], T1.[Dscription] as 'Item Descr.', T1.[Quantity], T1.[Price] as 'Sale price', T1.[LineTotal] as Revenues, T1.VatSumSy as 'Revenues VAT', T0.TotalExpns as Freight, T8.[Segment_0], T8.[AcctName], T3.U_ProductGroups, T3.U_ProductCategories, T5.[GroupName],T2.U_Dtmdiv,T6.Name as Country,
    T7.[ItmsGrpNam],T4.SlpNAme, T0.[U_ORDERED], T0.[U_TMPREFERENCE], T0.[U_CLASS], T0.[U_JOBS], T0.Comments, T0.NumAtCard
    INTO #T_TEMP
    FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN OITM T3 ON T1.ItemCode = T3.ItemCode INNER JOIN OSLP T4 ON T0.SlpCode = T4.SlpCode INNER JOIN OCRG T5 ON T2.GroupCode = T5.GroupCode
    LEFT OUTER JOIN OCRY T6 ON T2.Country = T6.Code INNER JOIN OITB T7 ON T3.ItmsGrpCod = T7.ItmsGrpCod INNER JOIN OACT T8 ON T1.AcctCode = T8.AcctCode
    where T0.[DocDate] >=  '[%FROM]' and T0.[DocDate] <=  '[%TO]'
    UNION ALL
    SELECT T0.[CardCode] as 'Cust. No.', T0.[CardName] as 'Cust. Name', T0.[DocNum] as Document, T0.[DocCur] as Currency, T1.Rate, T0.[DocDate],T1.[ActDelDate] as 'Delivery date', datepart(MM,T0.[DocDate]) as Month,datepart(yyyy,T0.[DocDate]) as Year, T1.TotalFrgn, T1.[SubCatNum] as 'BP Catalog',T1.[ItemCode], T1.[Dscription] as 'Item Descr.', -T1.[Quantity], T1.[Price] as 'Sale price', -T1.[LineTotal] as Revenues, -T1.VatSumSy as 'Revenues VAT' , -T0.TotalExpns as Freight, T8.[Segment_0], T8.[AcctName],  T3.U_ProductGroups, T3.U_ProductCategories, T5.[GroupName],T2.U_Dtmdiv,T6.Name as Country,
    T7.[ItmsGrpNam],T4.SlpNAme, T0.[U_ORDERED], T0.[U_TMPREFERENCE], T0.[U_CLASS], T0.[U_JOBS], T0.Comments, T0.NumAtCard
    FROM ORIN T0  INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN OITM T3 ON T1.ItemCode = T3.ItemCode INNER JOIN OSLP T4 ON T0.SlpCode = T4.SlpCode INNER JOIN OCRG T5 ON T2.GroupCode = T5.GroupCode
    LEFT OUTER JOIN OCRY T6 ON T2.Country = T6.Code INNER JOIN OITB T7 ON T3.ItmsGrpCod = T7.ItmsGrpCod INNER JOIN OACT T8 ON T1.AcctCode = T8.AcctCode
    where T0.CANCELED = 'N' and T0.ObjType = 14 and T0.[DocDate] >=  '[%FROM]' and T0.[DocDate] <=  '[%TO]'
    SELECT [Cust. No.], [Document], T0.[Currency], (CASE WHEN ISNULL(T0.Rate,0)=0 OR T0.Rate = 0 THEN Null  ELSE T0.Rate END) as 'Rate', [DocDate], [Delivery date], [Month], [Year], (CASE WHEN T0.TotalFrgn = 0 THEN Null ELSE T0.TotalFrgn END) as 'Total FC', [BP Catalog], T0.[ItemCode], [Item Descr.], [Quantity], (CASE WHEN ISNULL(T0.Rate,0)=0 OR T0.Rate = 0 THEN T1.Price  ELSE T1.Price * T0.Rate END) * T0.Quantity as 'Purchase Price', (CASE WHEN ISNULL(T0.Rate,0)=0 OR T0.Rate = 0 THEN T1.Price  ELSE T1.Price * T0.Rate END) as 'Costs', [Revenues], [Revenues VAT], [Freight], (CASE WHEN ISNULL(T0.[Freight],0)=0 OR T0.[Freight] = 0 THEN Null  ELSE T0.[Freight]/10 END) as 'Freight GST', [Sale price], [Segment_0], [AcctName], T0.U_ProductGroups, T0.U_ProductCategories, [Country], [U_Dtmdiv] as 'Business Line', [Cust. Name], [SlpNAme] as 'KAM', [GroupName], [ItmsGrpNam], T0.[U_ORDERED], T0.[U_TMPREFERENCE], T0.[U_CLASS], T0.[U_JOBS],  T0.Comments,  T0.NumAtCard as 'Customer Ref.No.'
    FROM #T_TEMP T0 INNER JOIN ITM1 T1 ON T0.ItemCode = T1.ItemCode LEFT JOIN OPLN T2 ON T1.PriceList = T2.ListNum LEFT JOIN ORTT T3 ON T0.DocDate = T3.RateDate AND T1.Currency = T3.Currency
    WHERE T2.ListName = 'PURCHASE'
    ORDER BY [DocDate],[Document]
    ----This query was written by someone else. I am trying to add a data field for the Ship To State for a sales tax reporting analysis. I know I need field StateS in INV12 table, but I keep getting errors. OINV Addresss2 is the entire shipping address, but I need to specifically add just the state. do I have to add an INNER JOIN INV12 T9 ON T0.Address2=T9.StateS????
    Many thanks in advance

    Hi Courtney,
    Indeed, you need to first join in the INV12 table, however the linking fields are DocEntry, and remember to use a unique table alias (so far you have used T0 to T8):
    INNER JOIN INV12 T9 ON T0.DocEntry = T9.DocEntry
    Next, because the query contains a UNION ALL clause, you need to make sure that you add a dummy / place holder field in the ORIN part for the StateS field. The StateS field is a nchar or nvarchar type field, so your dummy /  place holder field should be something like ' ' .
    Regards,
    Johan

  • Simple Query Question - How do I return the Last 3 records of a Table?

    Question.
    For example, I have a table that has 50 records.
    How do I, specify in SQL to only return the last 3 records of the table.
    Select a.* from table a where ????

    I was just trying to show an example to a friend on
    how something like this would work and if it was even possible. But it won't work. Here's a simple example:
    SQL> create table emp
      2  (id)
      3  as
      4  select object_id
      5  from   all_objects
      6  order  by object_id;
    Table created.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
         40830      55891
         40831      55892
         40832      55893So far, so good. These are the "last 3" rows inserted. Now delete a bunch of rows and insert 3 new ones:
    SQL> delete emp where id < 40000;
    33423 rows deleted.
    SQL> commit;
    Commit complete.
    SQL> insert into emp values (60000);
    1 row created.
    SQL> insert into emp values (60001);
    1 row created.
    SQL> insert into emp values (60002);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
          7410      55891
          7411      55892
          7412      55893Here's the problem. Even though the "last 3 rows" are 60000 - 60002, I still get the same ones as the first query.

  • Oracle 10g and parallel query question

    Hi Oracle on SAP Gurus!
    We are currently thinking of activating parallel query for certain segments (large application tables and indexes). We searched in SAPNet and SDN and have also studied the SAP Note 651060. But we did not find a complete answer to the following question which is very important for us:
    Which kinds of queries (despite from full table scan and index scan in partitioned indexes) support parallel queries and which ones do not support parallel queries?
    This is important for us to find out whether we have candidates for parallel queries or not.
    Thanx for any hint!
    Regards,
    Volker

    But why do you not propose to use parallel query in OLTP systems?
    If the queries are accessed very frequently you will just run out of cpu and io ressources. OLTP systems are (historical) typically multi user systems. You can off course use PQ for 'single user' activities, like index rebuilds, some batchjobs, but you shouldn't do for frequent user queries.
    If you have time look at this interesting Article [Suck It Dry - Tuning Parallel Execution|http://doug.burns.tripod.com/px.html]
    It is quite old, and you don't have to read all tech details, but i recommend having a look at the conclusions at the end.
    May it make sense to use partitioning of these tables in conjunction with parallel query?
    I know some guys, who do partitioning on OLTP systems, even SAP systems. But they don't use PQ then. The use partitioning to work on a smaller set of data. In your case the range scans, would need to scan only one partition, saving buffer cache and effectively speeding up execution. So you don't need PQ to scan all partitions at all, this would be a typical OLAP approach.
    Best regards
    Michael

  • General JPA query question

    Hello world,
    I'm new to JPA 2.0 and there are few things I don't understand.
    BTW: I can't figure out the keywords to search for this question, so please pardon me if it's one of the most asked.
    Using the Preview, I've seen that alignment went straight to Hell, so I tried to make this as readable as I could using pipes in place of white spaces in the result sets.
    I have a couple of tables:
    CUST table (for customers):
    CUST_ID (pk, integer)
    CUST_NAME (varchar)
    ORD table (for orders):
    ORD_ID (pk, integer)
    ORD_STATUS (char) can be: N for new, S for shipped, D for delivered
    CUST_ID (fk, integer)
    The relationship is, of course, a "one to many" (every customer can place many orders).
    Content of the tables:
    CUST_ID|CUST_NAME
    1|elcaro
    2|tfosorcim
    3|elppa
    ORD_ID|ORD_STATUS|CUST_ID
    2|N|1
    3|N|1
    4|N|1
    5|S|1
    6|S|1
    7|D|1
    8|D|1
    9|D|1
    10|D|2
    11|N|2
    12|S|3
    13|S|3
    Here's how I annotated my classes:
    Customer.java:
    @Entity(name = "Customer")
    @Table(name = "CUST")
    public class Customer implements Serializable
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "CUST_ID")
    private Integer id;
    @Column(name = "CUST_NAME")
    private String name;
    @OneToMany(mappedBy = "customer")
    private List<Order> orders;
    // Default constructor, getters and setters (no annotations on these)
    Order.java:
    @Entity(name = "Order")
    @Table(name = "ORD")
    public class Order implements Serializable
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "ORD_ID")
    private Integer id;
    @Column(name = "ORD_STATUS")
    private Character status;
    @ManyToOne
    @JoinColumns
    @JoinColumn(name = "CUST_ID", referencedColumnName = "CUST_ID")
    private Customer customer;
    // Default constructor, getters and setters (no annotations on these)
    Everything works just fine, the following JPQL query yields the results I expected:
    select c from Customer c
    it returns three objects of type Customer, each of which contains the orders that belong to that customer.
    But now, I want to extract the list of customers that have orders in status 'N', along with the associated orders (only the status 'N' orders, of course).
    Back in the good ol' days I would have written an SQL query like this:
    select c.cust_id, c.cust_name, o.ord_id, o.ord_status
    from cust c
    inner join ord o on (o.cust_id = c.cust_id)
    where o.ord_status = 'N'
    and it would have returned the following result set:
    CUST_ID|CUST_NAME|ORD_ID|ORD_STATUS
    1|elcaro|2|N
    1|elcaro|3|N
    1|elcaro|4|N
    2|tfosorcim|11|N
    The following JPQL query, however, doesn't yield the expected results:
    select distinct c from Customer c join c.orders o where o.status = 'N'
    it returns the correct set of customers (customer 'elppa' doesn't have any status 'N' order and is correctly excluded), but each customer contains the full set of orders, regardless of the status.
    It seems that the 'where' clause is only evaluated to determine which set of customers has to be extracted and then the persistence provider starts to navigate the relationship to extract the full set of orders.
    Thinking a little about it, I must admit that it makes sense.
    I then tried out another JPQL query:
    select c, o from Customer c join c.orders o where o.status = 'N'
    this JPA query yields results that are similar to the ones produced by the previous SQL query: each result (4 results as expected) is a 2-object array, the first object is of type Customer and the second object is of type Order. But, again, the objects of type Customer contain the full set of related orders (as I expected, this time). Not to mention the fact that now the orders are not contained in the Customer objects, but are returned separately, just as in an SQL result set.
    Now the question is:
    Is it possible to write a JPA query that filters out, not only the customers that don't have an order in status 'N', but the related orders (fetched during relationship navigation) that are not in status 'N' as well?
    What I'd like to be able to get is a 2-customer result where each customer contains only its status 'N' orders.
    I read the Java EE 6 Tutorial and one of the examples (the Order Application) has a schema that is similar to mine, but I couldn't find a query like this (in the downloaded source code).
    Although I think the above is standard behavior, I use an Oracle Weblogic 12c server (through its Eclipse adapter) and the persistence provider appears to be EclipseLink.
    Thanks in advance.
    Best regards,
    Stefano
    Edited by: user11265230 on 17-apr-2012 14.11

    Hello,
    When returning an entity from JPQL, it gives you the entity as it is in the database. Your "select distinct c from Customer c join c.orders o where o.status = 'N'" is asking for all customers that have an order with a status of 'N', so that is what it gives you. There is no condition to filter anything on the relationship when building the Customer object in JPA - doing so would mean returning a managed entity that does not reflect what is in the database. This would affect other queries, since JPA requires that queries return the same instance of an entity regardless of the query that is used to bring it back. So a query using your "where o.status = 'N'" would cause conflicting results when used with a query using "where o.status = 'Y'". And these queries would make the EntityManager unable to determine what has changed on the returned objects.
    EclipseLink does have the ability to filter over relationships, it is just not available through standard JPA and I would strongly discourage it. Instead of querying for Customers, why not change the query to get Orders instead -
    "select o from Customer c join c.orders o where o.status = 'N'". Assuming Orders have a ManyToOne back reference to their Customer, this will mean you do not need to travers the Customer-> order relationship. If using
    "select c, o from Customer c join c.orders o where o.status = 'N'"
    I am not sure why you would use the orders from the returned customers instead of the orders returned in the results though.
    You could also return "select c.id, c.name, o.id, o.status from Customer c join c.orders o where o.status = 'N'" which is the equivalent of what you would get from the SQL you initially posted.
    Regards,
    Chris

  • Left Join Query Question

    Version 10.2.0.4.0
    I have a question on the expected behavior of the query below.
    When I run the query below with the constraint on t1.partid = 789,  I get the query result t2.Indicator showing "SPECIAL" as expected.
    However, if I remove the constraint, and return all orders and parts, for the "789" part, the Indicator column is null.
    select t1.orderid, t1.partid, t2.Indicator
    from Orders a left outer join
    select partid, 'SPECIAL' as Indicator
    from vendors
    where vendorname like '%ABC%'
    ) t2
    on t1.partid = t2.partid
    where t1.partid = '789'
    I can address the issue with a case statement (below) or likely restructuring into a better statement. 
    But I'm just curious if this is expected or if there is some SQL rule being violated in the first example.
    I tried to search for this to see if it was already addressed but didn't have much luck.
    This works:
    select t1.orderid, t1.partid,
    case when t1.partid is not null then "SPECIAL" else null end as Indicator
    from Orders a left outer join
    select partid, 'SPECIAL' as Indicator
    from vendors
    where vendorname like '%ABC%'
    ) t2
    on t1.partid = t2.partid

    Sorry, it's been a while since I posted and should have read the rules.  And I didn't properly reference the alias.  So Post #1 was bad. 
    When I mockup a small set of data (shown below), I don't get the error.  The original query actually joins to a few other (seemingly) irrelevant tables and I tried to simplify it here  So I guess if I can't replicate it, then there might not be much assistance that can be provided.
    This was more of a curiousity than anything else to see if perhaps someone came across this before.
    For what it's worth:
    create table t1 (orderid number,
                 partid varchar2(20)
    create table t2
            (vendorid varchar2(20),
             partid varchar2(20)
    insert into t1 values(1, '123');
    insert into t1 values(2, '456');
    insert into t1 values(3, '789');
    insert into t2 values ('ABC','789');
    insert into t2 values ('DEF','123');
    insert into t2 values ('EFG','456');
    insert into t2 values ('ABC','7891');
    insert into t2 values ('DEF','1231');
    insert into t2 values ('EFG','4561');
    select t1.orderid, t1.partid, t2.Indicator
    from t1 left outer join
    select partid, 'SPECIAL' as Indicator
    from t2
    where vendorid like '%ABC%'
    ) t2
    on t1.partid = t2.partid
    the query that gives unexpected behavior is (although I can't replicate on this simplified version):
    select t1.orderid, t1.partid, t2.Indicator
    from t1 left outer join
    select partid, 'SPECIAL' as Indicator
    from t2
    where vendorid like '%ABC%'
    ) t2
    on t1.partid = t2.partid

  • SQL Query Question

    Hi,
    I am trying to filter my output from the query based on some conditions but not able to figure out how. May be I am just overlooking at the issue or is it something tricky.
    So, I have a query returning 4 rows of output out of which I need to filter the rows. I have created a table from the result of the query that I need to filter to make it simple. So below is my create table script and values that are obtained from my original query.
    CREATE TABLE TEMPACCT
      SOURCEKEY           NUMBER,
      FLAG                VARCHAR2(1),
      ITEMID              NUMBER(9)                 ,
      ITEMNAME            VARCHAR2(10)               ,
      ITEMKEY             NUMBER(9)                
    Insert into tempacct values (0, 'N', 100, 'ITEM1' , 9647);
    Insert into tempacct values (0, 'N', 200, 'ITEM2' , 9648);
    Insert into tempacct values (9648, 'N', 100, 'ITEM3' , 9813);
    Insert into tempacct values (9647, 'Y', 100, 'ITEM4' , 9812);
    SQL> select * from tempacct;
    SOURCEKEY F     ITEMID ITEMNAME      ITEMKEY
             0 N        100 ITEM1            9647
             0 N        200 ITEM2            9648
          9648 N        100 ITEM3            9813
          9647 Y        100 ITEM4            9812
    SQL> Tempacct table is the table created from the resultset of my original query.
    So from the above output, what I need is 3 rows. The logic to filter out the row is - If any of the row thathas sourcekey that is same as Itemkey in any of the 4 rows and flag is Y then remove the row which have flag =N and only display the one with Falg = Y.
    Ok, so, in this case the desired output would be
    SOURCEKEY F     ITEMID ITEMNAME      ITEMKEY
             0 N        200 ITEM2            9648
          9648 N        100 ITEM3            9813
          9647 Y        100 ITEM4            9812So here we compared between the first row and the fourth row, and since the sourcekey in fourth row is same as itemkey in first row and Flag is 'Y' for fourth row, we keep 4th row and remove the first row since the flag is 'N'. (and sourcekey is 0. the row that gets removed will always have sourcekey =0) .
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - ProductionAppreciate your help.

    Hi,
    ARIZ wrote:
    Although the original question is already been answered, I had another small modification to the same question and also seeking some clarification. I do not want to open a new thread just for a similar question.I think you'll get better replies faster if you do start a new thread.
    Not counting this one, there have been 13 replies to this thread. Not many people who havn't already been participating in this thread are going to start reading a thread with 13 replies. Those who do are going to waste a lot of time reading about issues that have already been resolved, and the are likely to understand the remaining issues incorrectly.
    I have been following the thread from the beginnning, and I'm starting to get confused about what the unresolved issues are.
    I believe there are two things you still need:
    (1) An explanation of the solution I posted yesterday, involving the analytic COUNT function.
    (2) A solution for a new problem involving the same tables
    If I got that wrong, start a new thread, asking just what you need to know. Copy any relevant parts (like the CREATE TABLE and INSERT statements) from this thread. You can include a link to this thread, but do your best to make sure people don't have to use it.
    I realize that's more work for you, but getting the best results, and getting them quickly, sometimes does require more work.
    <h2>(1) An explanation of the solution I posted yesterday, involving the analytic COUNT function.</h2>
    ARIZ wrote:
    Hi Frank,
    Just out of curiosity, I was trying to understand the Count analytical function that you have used in the solution.
                    COUNT ( CASE
                                 WHEN  ac.flag = 'Y'
                           THEN  1
                             END
                        ) OVER ( PARTITION BY  CASE
                                                   WHEN  sourcekey = 0
                                       THEN  acctkey
                                       ELSE  sourcekey
                                               END
                                  )     AS y_cntSo what I am thinking is, this would first partition the row with acctkey ( where sourcekey =0) and sourcekey and then within that partition, it will check whether ac.flag = Y or not, if it is 'Y' then it would return count as 1 else 0. Am I correct? In the mean time I am also reading the tutorials on Count() analytical query. I'm not sure I understand your explanation.
    This is not partitioning first by x, and then by y. There is only one expression in the PARTITION BY clause. Most often, a PARTITION BY clause refers to some column in the table, for example:
    SELECT  ename
    ,       job
    ,       sal
    ,       AVG (sal) OVER (PARTITION BY job)  AS avg_sal_for_job
    FROM    scott.emp;This divides the result set into mutually exclusive parts; there will be as many such parts as there are distinct values for the PARTITION BY column. In the simple query above, if there happen to be 5 different values for job, you will get 5 independent averages.
    In your problem, there is no one column that defines a partition. That is, these two rows belong to the same partition:
    . SOURCEKEY F   ACCTKEY
             0 N       9647
          9647 Y       9812even though none of the 3 columns are the same. We could create a view that had a single column, telling to which partition each row belonged, like this:
    . SOURCEKEY F   ACCTKEY PART_NUM
             0 N       9648     9648
             0 N       9647         9647
          9648 N       9813         9648
          9647 Y       9812         9647where part_num is the result of a CASE expression:
    CASE
        WHEN  sourcekey = 0
        THEN  acctkey
        ELSE  sourcekey
    ENDWe could then use that new column, part_num, in a (very simple) PARTITION BY clause. But there is no need to create a view, even an in-line view, for that: we can (and I did) use the CASE expression directly in a (not so simple) PARTITION BY clause.
    Why did I use COUNT? The important thing about each partition is whether or not it includes any rows with flag='Y'. I don;t know of any function that directly answers that question. There are lots of ways to get the correct answer, but I think the one that corresponds most closely to the question we really want to ask:
    "Do any rows have flag='Y'?" is
    "How many rows have flag='Y'?"
    The analytic function COUNT (x) returns a number (possibly 0) of rows in the partition where x is not NULL. So, as the argument to COUNT, I used
    CASE
        WHEN  ac.flag = 'Y'
        THEN  1
    --  ELSE  NULL          -- I did not explicitly say this, but it is the default
    ENDwhich returns either
    (a) the literal number 1 or
    (b) NULL
    Instead of the literanl number 1, I could have used any literal or expression, of any data type, that is not NULL). all that matters is we produce something non-NULL for COUNT to count.
    <h2>(2) A solution for a new problem involving the same tables</h2>
    Also, I was trying to modify this query to fit my other similar requirement where I would need following output
    Original output:
    SOURCEKEY F    ACCTKEY
    0 N       9648
    0   N      9647
    9648 N       9813
    9647 Y       9812
    So, the query should be smart enough to return only the last two rows where sourcekey >0 which is
    SOURCEKEY F    ACCTKEY
    9648 N       9813
    9647 Y       9812
    And In case there are only first two 2 rows in the table then , it should return only those two row and not check for sourcekey > 0 which would be .
    SOURCEKEY F    ACCTKEY
    0 N       9648
    0   N      9647 Is it something that I should be using analytical function to solve this requirement. I am trying to accomplish this new requirement.If I understand this problem correctly, it does indeed involve mutually exclusive divisions, but in this problem, the divisions correspond more closely to a single column in the table. We want to divide the table into two mutually exclusive groups:
    (A) rows where soucekey > 0, and
    (B) rows where sourcekey = 0
    We could do that with a CASE expression, but there happens to be a built-in function that works very nicely.
    SIGN (sourcekey) returns
    (A) 1 if sourcekey > 0, and
    (B) 0 if sourcekey = 0
    But what do we want to do with those divisions? We want to display rows only from the "best" of those divisions, where division (A) is coinsidered "better" than division (B). That is, if there are any rows in division (A), then we want to display only rows in division (A), but if there are no rows in division (A), then (and only then) we want to display rows in divison (B).
    This is an example of a Top-N Query , where we want to display N items from the top of an ordered list. A typical top-N query uses an analytic function (either ROW_NUMBER, RANK or DENSE_RANK, depending on how we want to handle ties) to assign numbers to each row (lower numbers for the "better" rows), and then uses "WHERE f <= n" to display only the n "best" ones. (A special case, though a very common one, is where N=1, that is, we're only interested in the row (or rows, if there happens to be a tie) with the "best" value. In this case, most people find it cleare to say "WHERE f = 1" ratehr than "WHERE f <= 1". Your problem is an exmple ot that special case.)
    SELECT  sourcekey
    ,     flag
    ,     acctkey
    FROM     (
             SELECT  ac.sourcekey
             ,         NVL (ac.flag, 'N')     AS flag
             ,         ac.acctkey
             ,         DENSE_RANK () OVER (ORDER BY  SIGN (sourcekey)     DESC)     AS division_num
                FROM    itemtable     i
             ,         finance     f
             ,         acct     ac
               WHERE   i.itemtableid1      = f.parentid1
               AND         i.itemtableid2      = f.parentid2
             AND         f.financekey      = ac.financekey
               AND         i.parenttableid      = 19063
    WHERE     division_num     = 1
    ;Notice I talked about "mutually exclusiive *divisions* " above, not "mutually exclusive *partitions* ".
    There is no PARTITION BY in the analytic clause above. PARTITION BY means we want a separate, independent caluclation for each partition. Here, we want one single numbering for the entire result set.
    We want all rows that tie for the "best" to be numbered 1, so we have to use DENSE_RANK (or RANK) rather than ROW_NUMBER.

  • Commission report Query Question

    The inbuilt Commission Report is run by the following query:
    SELECT T0.DocNum, T0.DocType, T0.DocTotal, ( T0.DocTotal - T0.VatSum) As "Net Income"  , T1.SlpName, T1.Commission, ( ( T0.DocTotal - T0.VatSum)*( T1.Commission/100)) As "Sum_Commissions" FROM OINV T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode WHERE T1.SlpName  = N'[%0]' AND T0.DocDate >= '[%1]' AND  T0.DocDate <= '[%2]'
    However, I have a need to change this query to solve a problem:
    If AFTER the Invoices are added to the system, I go back to the Invoice and change/add the Employee Name to the transaction line, the query ignores these additions made. Can I change the query so the Commission Report takes into account changes made to the employees' field AFTER invoices are posted to the system (SAP allowes me to make such changes to the employee)
    In other words I would like the Query to look at the Emploee field AFTER I make changes and give me an updated report.
    i am aware that SAP does not allow changes to the Invoice AFTER posting them to the system but it seems to allow changes to the Commission/Employee field, so I should be able to run a Commission report after I make these changes.
    Thank you
    Robert

    Hi SUDA,
    Yes I mean SALES EMPLOYEE. It seems strange to me as well that this report will ignore the information in this field. I have checked this again and what seems to happen is as follows: Say I have invoice no 712 marked to Employee=Erica and I run the commission report for Erica and invoice 712 correctly appears on the report. Then I go back and change the Employee Name on the Invoice 712 (on each line) to Robert and I run the report again. I would expect that Inv 712 will be included in this report (commission report for Robert) but for some strange reason, IS NOT.
    In fact INV 712 is still associated with ERICA although I have changed the SE to Robert- please check this out?
    Thanks
    Robert

  • Urgent , Two Query questions ...

    Hello everybody ,
          i have created a query in our production system . but i found some people can change my query setting (ex : my local fileds & selection fields ) , has any one can tell me how can i disable the 'Change' function in 'SQ01' ? many thanks !
    (i also use 'su24' to check the authorzation object in 'SQ01' , but i don't know which one can help me to solved this case)
          another question that is when i execute the query i found one of the field's sequence was wrong . but this query is used everyday & nobody has changed it . but when i use  sort this function to make it & it seems ok . therefore i think the problem is in the table index , right ? Has anyone can tell me how to check it ?
    Best Regards,
    Carlos

    hi Ramki
         the query is made by ourselves . the data is only fetched from the billing table (vbrk & vbak) . but today i found some filed's sequence was wrong & i don't know what cause this .
    another problem is that could you tell me how to disable 'Change' function in 'SQ01' ?
    many thanks ~
    Best Regards,
    Carlos

  • Named query question

    Hi Guys,
    I have the following problem - I know I did something wrong, but I cannot figure out how to correct it. Here is my question:
    I have a table tableA, with composite key (col1, col2, col3, col4). I mapped the table, and create a Toplink named query (findCol3List)as such:
    select distinct col3
    from tableA
    where col1=#col1 and col2=#col2
    I created an EJB session method getCol3List(col1, col2) -
    now when I run the application to call this EJB method, I got the following error at line:
    List results = (List)session.executeQuery("findCol3List", String.class, params);
    Exception Description: Missing descriptor for [java.lang.String] for query named [findCol3List].
    I know there are multiple mistakes in my approach, but with my limited Toklink knowledge, I could not figure out.
    Any help with be appreciated!

    hello,
    The executeQuery method is trying to look up the "findCol3List" in the descriptor for the class passed in. It is complaining because you passed in String.class which does not have a valid descriptor.
    How/where did you define the named query? Chances are you defined it in the class used for TableA, and so should specify it in the executeQuery method:
    session.executeQuery("findCol3List", tableA.class, params);
    Best Regards,
    Chris

  • Creating SAP QUERY - question about tables in buisness transactions.

    Hello.
    I am pretty new to SAP.
    I want to create a query, as i so far have successfully done by creating a join in transaction SQVI.
    I am useing several tables;
    CRMD_ORDERADM_H
    CRMD_ORDERADM_I
    CRMD_ORDER_INDEX
    I have two questions.
    1: I try to join CRMD_ORDER_INDEX-PARTNER_NO with BUT000-PARTNER, but it won't do the trick. After a join like this i would like to join BUT000 with ADRC . Can someone explain how i could do this?
    2: I want join CRMD_ORDERADM_I with all the partners for the specific Item. (sold-to-party, shipping-party and so on). Can anyone tell me which table(s) i can find this in, and what fields to join.
    I will appreciate any answer to this

    Hi,
    For the second question, enter your transaction number ( Object ID ) into <b>CRMD_ORDERADM_H</b>  table. Pass the guid to table <b>CRMD_LINK.</b>
    Take set guid from CRMD_LINK and pass it to <b>CRMD_PARTNER</b>.
    You will get all the partners in that transaction
    regards,
    Prashant
    <b>Kindly Reward the points if helpful !</b>

  • Web Service Query Question

    I have a process that is going through each account record and doing some processing on it.
    This is a time consuming process. It takes close to 20 minutes to complete.
    I would like to provide a better status message to my customer to let them know how much longer the process should take.
    My question is:
    Can I retrieve the count of the number of records that would be returned based on the query criteria I am using?
    I would use this to provide a status message like
    "Processing account 50 of 120,000"

    Hi All,
    Recently we also had the same requirement, count the number of records and we achieved it by reports.
    1. create a report which generates the simply total count of records.
    2. on your custom page / application access that report and get the count.
    Dinesh
    CRMIT

  • Complex Query Question

    I am doing a 9-1-1 reporting system. I am selecting calls by
    Agency and type of call for a given month. That works fine, but I
    need them printed in desending sequence by number call far a call
    type. Don't see anyway to accomplish that with one query.
    Is that a way? If not, the second part of this question is
    that I have not created a table using SQL. I need 3 fields, Field_A
    is Text (9 positions); Field_B is Text (40 Positions) and the last
    is my summarized count from the query. How do I create a Table to
    support this function?
    Query
    <cfquery name="GetEventCount"
    datasource="JasperCountyDB">
    select count(AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
    from aeven
    where ((AG_ID = '#Session.InquiryAgencyCode#')
    AND (CURENT = 'T') AND (CDTS LIKE '#EventReportDate#'))
    group by AG_ID, TYCOD, TYP_ENG, CURENT
    </cfquery>
    Thanks for any guideance that you can provide.
    Ron

    Your question wasn't very clear, but if you only want to sort
    them by the count in descending order, just ORDER BY 1 DESC.
    <cfquery name="GetEventCount"
    datasource="JasperCountyDB">
    SELECT COUNT(AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
    FROM aeven
    WHERE AG_ID = '#Session.InquiryAgencyCode#'
    AND CURENT = 'T'
    AND CDTS LIKE '#EventReportDate#'
    GROUP BY AG_ID, TYCOD, TYP_ENG, CURENT
    ORDER BY 1 DESC
    </cfquery>
    Phil

Maybe you are looking for

  • I have 1 itunes account, 2 iphones- want to share some but not all media- how?

    iPhone is SO easy to use, but this in iTunes has me stumped.  My husband won't sync his phone because he doesn't want ALL of my apps, contact info, music, etc.  But SOME of the apps and music we do want to share... from what I understand I can do thi

  • OS X fails to open quarantined files

    Hi, Since doing a fresh install of snow leopard on release date I have had several problems with the OS X I have googled but can't seem to find any reference to this issue; When I first boot into OS X everything works fine and it stays that way for h

  • Mainstage 2 not loading mainstage 1 files properly

    Hi there, running a 2008 macbook pro 15", 4gb ram. Had no problems installing the logic studio 2009 upgrade, logic's working fine. But Mainstage 2 won't load my old Mainstage files, keeps saying the files are corrupt. If the file does load, it is all

  • Auto numbering in TOC tags

    I am creating books that use auto numbering in the headings. For example: 1.0 Introduction 2.0 First chapter 2.1 First topic 2.2 Second topic 2.2.1 Sub topic 1 When I generate the TOC, the numbers do not appear. I do not see any information in the Us

  • 651 shutting down on heavy cd use?

    I bought a 651 system for my wife last fall; all standard equipment, nothing extreme or exciting. My four-year-old tried playing some games on it; they're all older and play directly from the cd as opposed to installing on the drive. Without fail, ev