Regd; paging query help.

hi friends,
can anyone help to create paging query with rownum.?

http://www.blahstuff.com/oldstuff/2005/12/08/363/paging-oracle-results/
read here

Similar Messages

  • Query Help-2

    Query Help:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
    It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
    The above was my previous posting, which was not clear..so Iam restating my problem as follows....
    I have the following tables
    Customer(custID, Name, Address)
    Order(custID, OrderID, orderDate)
    CreditCard(custID, creditCard#, creditCardType)
    Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
    Order:
    100,A001,11/22/03
    100,A002,11/24/03
    100,A003,12/02/03
    CreditCard:
    100,42323232..., VISA
    100,5234234...., MASTER
    Now how can I get
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    data in minimum no. of records....
    I think I have made my query clear..
    now please help me guys...
    thanks so much for your help.

    You are right.
    But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
    Can you please help me with the query
    if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
    With the following fields in my query result,
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    from Customer, Order, CreditCard tables
    Thanks so much for your htlp

  • SQL Query Help - Is this possible or impossible????

    Hi guys,
    I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
    For example,
    I have 2 tables
    The first table is:
    1) COMPANY create table company (manufacturer varchar2(25),
                                                          date_established date,
                                                          location varchar2(25) );My sample test date is:
    insert into company values ('Ford', 1902, 'USA');
    insert into company values ('BMW', 1910, 'Germany');
    insert into company values ('Tata', 1922, 'India');The second table is:
    2) MODELS create table models (manufacturer varchar(25),
                                                 model varchar2(25),
                                                 price number(10),
                                                 year date,
                                                 current_production_status varchar2(1) ) ;My sample test data is:
    insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
    insert into models values ('Ford', 'Galaxy', 12000,   2008, 0);
    insert into models values ('Ford', 'Escort', 10000, 1992, 1);
    insert into models values ('BMW', '318', 17500, 2010, 0);
    insert into models values ('BMW', '535d', 32000,   2006, 0);
    insert into models values ('BMW', 'Z4', 10000, 1992, 0);
    insert into models values ('Tata', 'Safari', 4000, 1999, 0);
    insert into models values ('Tata', 'Sumo', 5500,   1996, 1);
    insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer IN ('Ford', 'BMW', 'Tata')
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCWhat I want the query to output is this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               Sumo               5500               1998          1If current_production_status is 1 it means this particular model has been discontinued
    If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
    The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
    So the query should output the one row where current_production_status is 1 for each manufacturer.
    If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
    My query as it is above will output all the records where current status is 1 or 0 like this
    com.manufacturer        com.date_established          com.location          mod.model          mod.price          mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    Tata               1922                    India               Sumo               5500               1998          1
    Ford               1902                    USA               -               -               -          0                    
    Ford               1902                    USA               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               -               -               -          0
    Tata               1922                    India               -               -               -          0However this is not what I want.
    Any ideas how I can achieve the result I need?
    Thanks!
    P.S. Database version is '10.2.0.1.0'

    Hi Vishnu,
    Karthiks query helped...
    But this is the problem I am facing...
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer = 'Ford'
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCThe value of:
    and com.manufacturer = 'Ford'will be dependent on front end user input....
    When I run the query above I get all the rows where current_production_status is either 1 or 0.
    I only require the rows where current_production_status is 1.
    So if I amend it to look like this:
         and mod.current_production_status = 1This works....
    BUT if a user now passes in more than one manufacturer EG:
    and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
    So like this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
    Thanks you so much!
    This is really driving me insane :-(

  • Need a query help

    hii
    i need a query help
    i have two tables
    the 1st table will look like this
    associate id weekid no.of. hours
    4000 810 40
    4000 820 30
    4000 830 60
    4000 840 70
    2nd table will look like this
    associate id weekid no.of.hours
    4000 810 40
    4000 820 70
    4000 830 130
    4000 840 200
    so when i subtract the last two records frm each other in the second table the value should be equal to the no.of.hours in the first table.. for example
    the query shud consider the last record and one before the last record and the difference between two records shud be equal to the value in the 1st table
    for example
    consider week id 830 and 840
    in second table 830=130
    840=200
    when u subtraced both values the difference shud be equal to value in the 1st table for tht week id
    1 ---->>>> 840 - 830
    =200 - 130
    =70
    in first table 840 has 70 hrs
    like this it shud check with all records and it shud return only the records which are not equal
    regards
    srikanth

    This..?
    sql>select * from t1;
    A_ID W_ID HRS
    4000  810  40 
    4000  820  30 
    4000  830  60 
    4000  840  70 
    4000  850  80 
    sql>select * from t2;
    A_ID W_ID HRS 
    4000  810  40 
    4000  820  70 
    4000  830  130 
    4000  840  200 
    4000  850  260 
    sql>
    select a_id,w_id,hrs,sum_hrs
    from(
    select t1.a_id a_id,t1.w_id w_id,t1.hrs hrs,t2.hrs sum_hrs,
           t2.hrs - nvl(lag(t2.hrs)  over(order by t1.w_id),0) diff
    from t1,t2
    where t1.w_id = t2.w_id)
    where diff != hrs;
    A_ID W_ID HRS SUM_HRS 
    4000  850  80  260                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Regd:- hierarchy level query help.

    Dear Friends,
    i have query like below.
    select empid ,empname from employee; (Deptid FK with department master table.)
    now i want to display department name also in above query. from Select deptname from dept;
    in deprtment table master table data as below...
    deptid deptname
    1 IT
    2 SALES
    3 BOE
    4 ACCOUNTS
    but i want output like below...
    EMPID ENAME DEPTNAME
    101 JON SALES,BOE,IT
    102 JEK SYS,ACCOUNTS.
    how should written the query...?
    pls help.

    Try this
    with employee
    as
    select 100 empno, 'karthick' ename from dual
    union all
    select 101 empno, 'rajnish' ename from dual
    , dept
    as
    select 100 empno, 'IT' dname from dual
    union all
    select 100 empno, 'SALES' dname from dual
    union all
    select 101 empno, 'IT' dname from dual
    select empno, ename, ltrim(sys_connect_by_path(dname,','),',') dname
      from (
              select e.empno, e.ename, d.dname, row_number() over(partition by e.empno order by d.dname) rno
                from employee e
                join dept d
                  on e.empno = d.empno
    where connect_by_isleaf = 1
    start with rno = 1
    connect by empno = prior empno
       and rno = prior rno+1and
    Please consider the following when you post a question.
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Important query regd Inheritance.Urgent help please

    Hi,
    I have a query regarding regarding Inheritance
    This is the structure:
    Superclass: Object
    Subclass ListItem extends Object
    Subclass HandleListItem extends ListItem
    My question is:
    Can ListItem be an instance of HandleListItem??

    can ListItem be an instance of HandleListItem??yes - a variable typed as a ListItem can hold an instance of HandleListItem
    ie
    1) some ListItems are HandleListItems
    2) but not all ListItems are HandleListItems
    3) a HandleListItem is always a ListItem

  • Complex query help

    Hope someone can help with this.
    I have a database structure :
    table : photos
    Photo_ID (PK)
    Title
    Orientation
    etc
    table : keywords
    Keyword_ID (PK)
    Keyword
    Category
    table : photokeywords
    Photo_ID
    Keyword_ID
    I have a search page that uses checkboxes allowing users to
    search on keywords, that returns any photos which match the
    selected keywords.
    In the search page the checkboxes are created using an array,
    and are displayed as :
    //Display the checkbox
    echo "<td width=\"2%\">";
    echo "<input type=\"checkbox\"
    class=\"tickbox_".$row_type."\"";
    if (in_array($keyword['Keyword_ID'],$photokeywords)) { echo
    " checked"; }
    echo " name=\"ckbox[".$keyword['Keyword_ID']."]\"
    id=\"ckbox[".$keyword['Keyword_ID']."]\">";
    echo "</td>\n";
    Someone kindly helped me out some time ago to write a fairly
    complex (for me!) query that counts the matches, so enabling the
    results to be ordered by the number of matches, ie the most
    relevant matches first.
    The code for this is :
    //db session
    mysql_select_db($database_Photolibrary, $Photolibrary);
    if (isset($_GET['ckbox'])){
    // get profile keys
    $ckbox = array_keys($_GET['ckbox']);
    // sql string
    $sql = 'SELECT *, Count(*) As rank FROM photos, photokeywords
    WHERE photos.Photo_ID =
    photokeywords.Photo_ID AND photokeywords.Keyword_ID IN(' .
    implode(',', $ckbox).') GROUP BY
    photos.Photo_ID ORDER BY rank DESC, Title';
    $photos = mysql_query($sql) or die(mysql_error());
    $row_photos = mysql_fetch_assoc($photos);
    @$totalRows = mysql_num_rows($photos);
    The page I have is using Tom Muck's pages list and horizontal
    looper behaviours to display the results.
    Everything works fine except the pages list, where there is
    more than one page of results. I've emailed the ever helpful Tom
    who has advised me that the query may need to be constructed in DW,
    as the Pages List behaviour relies on DW's code to manage the
    paging.
    So I've gotten as far as the basic query code :
    <?php
    mysql_select_db($database_Photolibrary, $Photolibrary);
    $query_photos = "SELECT *, Count(*) As rank FROM photos,
    photokeywords WHERE photos.Photo_ID = photokeywords.Photo_ID AND
    photokeywords.Keyword_ID IN(' . implode(',', $ckbox).') GROUP BY
    photos.Photo_ID ORDER BY rank DESC, Title";
    $photos = mysql_query($query_photos, $Photolibrary) or
    die(mysql_error());
    $row_photos = mysql_fetch_assoc($photos);
    $totalRows_photos = mysql_num_rows($photos);
    ?>
    But am unsure where I need to call the ckbox values,
    previously :
    if (isset($_GET['ckbox'])){
    // get profile keys
    $ckbox = array_keys($_GET['ckbox']);
    in the DW construction.
    I've been playing around with different things in the query's
    variables, such as
    Name : Keyword_ID
    Default value : 1
    Run time value : $_GET['ckbox']
    but to no avail.
    If anyone can help out with this it'd be much appreciated.
    Cheers.

    Something like this?
    SQL> var P_DISCOUNT_RATE number
    SQL> var P_BASE_YEAR number
    SQL> var P_FUTURE_YEAR number
    SQL> exec :P_DISCOUNT_RATE := 0.1; :P_BASE_YEAR := 2003; :P_FUTURE_YEAR := 2009;
    PL/SQL-procedure is geslaagd.
    SQL> select sum(npd)
      2    from ( select nvl
      3                  ( ( select sum(sal)
      4                        from emp
      5                       where to_number(to_char(hiredate,'yyyy')) + 25 = :P_FUTURE_YEAR - l
      6                    )
      7                  , 0
      8                  ) / power(1 + :P_DISCOUNT_RATE, l) npd
      9             from ( select level-1 l from dual connect by level <= 1 + :P_FUTURE_YEAR - :P_BASE_YEAR )
    10         )
    11  /
                                  SUM(NPD)
    22248,89010313503176012567447578717301
    1 rij is geselecteerd.I counted 7 iterations for the values 2003 and 2009, so you might want to explain a little more.
    Regards,
    Rob.

  • Query help on Goods Receipt Query with AP Invoice

    Looking for a little help on a query.  I would like to list all the goods receipts for a given date range and then display the AP Invoice information (if its been copied to an AP Invoice).  I think my problem is in my where clause, I plagerized an SAP query to show GR and AP from a PO as a start.  SBO 2005 SP01.  Any help would be great appreciated.  Thanks
    SELECT distinct 'GR',
    D0.DocStatus,
    D0.DocNum ,
    D0.DocDate,
    D0.DocDueDate,
    D0.DocTotal,
    'AP',
    I0.DocStatus,
    I0.DocNum ,
    I0.DocDate,
    I0.DocDueDate,
    I0.DocTotal,
    I0.PaidToDate
    FROM
    ((OPDN  D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry)
    full outer join
    (OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry)
    on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
    WHERE
    (D1.BaseType=22 AND D1.DocDate>='[%0]' AND D1.DocDate<='[%1]')
    OR (I1.BaseType=20 AND I1.BaseEntry IN
    (SELECT Distinct DocEntry
    FROM PDN1 WHERE BaseType=22 AND DocDate>='[%0]' AND DocDate<='[%1]'))

    Hi Dalen ,
    I  believe it is because of the condition
    (D1.BaseType=22 AND D1.DocDate>='%0' AND D1.DocDate<='%1')
    OR (I1.BaseType=20 AND I1.BaseEntry IN
    (SELECT Distinct DocEntry FROM PDN1 WHERE PDN1.BaseType=22 AND DocDate>='%0' AND DocDate<='%1'))
    Try changing
    D1.BaseType=22 OR D1.DocDate>='%0' AND D1.DocDate<='%1
    PDN1.BaseType=22 OR DocDate>='%0' AND DocDate<='%1'))
    Lets see what would be the result . Lets have some fun with troubleshooting
    See what would be the difference in the result .
    Thank you
    Bishal

  • Query help: query to return column that represents multiple rows

    I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
    I need a query to find all names that occur in both of two separate locations.
    For example,
    bob usa
    bob mexico
    dot mexico
    dot europe
    hal usa
    hal europe
    sal usa
    sal mexico
    The query in question, if given the locations usa and mexico, would return bob and sal.
    Thanks for any help or advice,
    -=beeky

    How about this?
    SELECT  NAME
    FROM    <LOCATIONS_TABLE>
    WHERE   LOCATION IN ('usa','mexico')
    GROUP BY NAME
    HAVING COUNT(DISTINCT LOCATION) >= 2Results:
    SQL> WITH person_locations AS
      2  (
      3          SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      4          SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      5          SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      6          SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      7          SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      8          SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      9          SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
    10          SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
    11  )
    12  SELECT  NAME
    13  FROM    person_locations
    14  WHERE   LOCATION IN ('USA','Mexico')
    15  GROUP BY NAME
    16  HAVING COUNT(DISTINCT LOCATION) >= 2
    17  /
    NAM
    bob
    salHTH!
    Edited by: Centinul on Oct 15, 2009 2:25 PM
    Added sample results.

  • QUERY HELP!!! trying to create a query

    i'm creating a summary report
    i have a table with sale dates
    for example i have a table tab_1 and column saleDate as
    saleDat
    1923
    1936
    1945
    2003
    2005
    saleDate contains years and there are some missing years where no sale
    was made
    My report has to display years starting from earliest year
    so i have to create a query that starts with 1923
    but the problem is that I have to have years that are not in table.
    for example i have to display years 1924 which is not in table
    so the part of report has to look like
    1923 blah blah summary.........
    1924 "
    1925
    1926
    2005
    2006
    upto current year (2006 may not be in the table, but i have to display)
    i just need to know the query that can query all the years starting from
    the ealiest saleDate to current year
    thanks in advance

    Please write the query in the following form:
    SELECT a.year, --- place other columns from your table.
    FROM (SELECT (:start_num + rownum) year
    FROM all_tab_columns
    WHERE :start_num + rownum <= :end_num) a,
    tab_1 b
    WHERE a.year = b.saleDat(+);
    Note:
    1) if your start year and end year are 1923 and 2006. Then input as below:
    :start_num = 1922
    :end_num = 2006
    2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
    3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
    Hope this helps.
    - Saumen.

  • Pulling open invoices, and paid invoices with details (Query Help).

    Hello All,
    I am sure I messed something up in my joins. I am looking to pull a report of all invoices OINV for a month, then list details of any payment (if it is paid) next to it from RCT2. It is giving me a list of all of the paid invoices, but even though I have a LEFT JOIN it is not listing any of the invoices without payments.
    This is where I am now from the report wizard in Crystal.
    SELECT "OINV"."DocNum", "OINV"."SlpCode", "OINV"."CardCode", "OINV"."DocTotal", "OINV"."U_Commission", "OSLP"."SlpName", "RCT2"."DcntSum", "ORCT"."TaxDate", "OINV"."DocEntry", "OINV"."TotalExpns", "OINV"."CANCELED", "ORCT"."Canceled", "ORCT"."DocNum", "RCT2"."InvType"
    FROM   ("DBName"."dbo"."OINV" "OINV" LEFT OUTER JOIN "DBName"."dbo"."OSLP" "OSLP" ON "OINV"."SlpCode"="OSLP"."SlpCode")
    INNER JOIN ("DBName"."dbo"."ORCT" "ORCT" INNER JOIN "DBName"."dbo"."RCT2" "RCT2" ON "ORCT"."DocNum"="RCT2"."DocNum")
    ON "OINV"."DocEntry"="RCT2"."DocEntry"
    WHERE  "OINV"."CANCELED"='N' AND "ORCT"."Canceled"='N' AND "RCT2"."InvType"<=N'14'
    ORDER BY "OINV"."SlpCode", "ORCT"."DocNum", "ORCT"."TaxDate"
    Thank you in advance for any help you can give me.

    Hello Kiran,
    I thought about that, but my purposes for running the report is to determine commission based on the date that the invoice was paid, I need the TaxDate in ORCT as it relates to the payment in RCT2.
    Removing the ORCT.cancelled condition and the RCT2.invtype conditions now pulls all of the invoices, paid and unpaid. I know now I cant have them in my query, when the record does not exist in ORCT it doesnt have a value for cancelled, and when there is no record in RCT2 there is no invtype, and is filtered.
    Maybe I can say where ORCT.Canelled = 'N' OR ORCT.Cancelled = NULL, but I dont know if that would work.

  • Query Help for reporting on last receipt qty

    SBO Version: 8.82 PL11
    Hello Forum,
    I am looking for some help devising a command behind a crystal report. We are hoping to achieve the last receipt quantity. To arrive at this we would like it to get the last GRPO for an item and total the quantity on that particular GRPO. In addition to this, we want to consider all the lines on the document and SUM them.
    At present, the query I have is as follows:
    Select SUM(c0.Quantity) from PDN1 c0 WHERE c0.ItemCode = T1.ItemCode AND Shipdate = (select Max(ShipDate) from PDN1 C0  INNER JOIN OPDN c1 ON c0.DocEntry = c1.DocEntry where C0.Itemcode =T1.ItemCode AND c1.DocStatus <> 'C'))
    Any assistance would be greatly received.
    Thanks
    Sarah

    Hi Sarah,
    Please repost to the SAP Business One Application  space.
    -Abhilash

  • SQL Query help ( On connect By level clause)

    Hi all,
    I have this query developed with data in with clause.
    With dat As
      select '@AAA @SSS @DDD' col1 from dual union all
      select '@ZZZ @XXX @TTT @RRR @ZZA' col1 from dual
    Select regexp_substr( col1 , '[^@][A-Z]+',1,level) Show from dat
    connect by level  <= regexp_count(col1, '@');Current output :-
    SHOW
    AAA
    SSS
    DDD
    RRR
    ZZA
    TTT
    RRR
    ZZA
    XXX
    DDD
    RRR
    SHOW
    ZZA
    TTT
    RRR
    ZZA
    . . .1st row comes fine, But next row data is getting duplicated. And total record count = 30. I tried with some but didn't work.
    Expected output :-
    SHOW
    AAA
    SSS
    DDD
    ZZZ
    XXX
    TTT
    RRR
    ZZAI need some change on my query and I am not able to find that. So anybody can add on that or can also provide some different solution too.
    Thanks!
    Ashutosh

    Hi,
    When you use something like "CONNECT BY LEVEL <= x", then at least one of the following must be true:
    (a) the table has no more than 1 row
    (b) there are other conditions in the CONNECT BY clause, or
    (c) you know what you are doing.
    To help see why, run this query
    SELECT     SYS_CONNECT_BY_PATH (dname, '/')     AS path
    ,     LEVEL
    FROM     scott.dept
    CONNECT BY     LEVEL <= 3
    ;and study the results:
    PATH                                     LEVEL
    /ACCOUNTING                                  1
    /ACCOUNTING/ACCOUNTING                       2
    /ACCOUNTING/ACCOUNTING/ACCOUNTING            3
    /ACCOUNTING/ACCOUNTING/RESEARCH              3
    /ACCOUNTING/ACCOUNTING/SALES                 3
    /ACCOUNTING/ACCOUNTING/OPERATIONS            3
    /ACCOUNTING/RESEARCH                         2
    /ACCOUNTING/RESEARCH/ACCOUNTING              3
    /ACCOUNTING/RESEARCH/RESEARCH                3
    /ACCOUNTING/RESEARCH/SALES                   3
    /ACCOUNTING/RESEARCH/OPERATIONS              3
    /ACCOUNTING/SALES                            2
    /ACCOUNTING/SALES/ACCOUNTING                 3
    84 rows selected.

  • Query Help required to Connect JDT1 with OINV tables

    Dear Experts,
    I have the following query which gives me the customer ageing report. I want some addtional fields from the OINV table and the document numbering table like Document Series Name, AR Invoice document Number,AR invoice remarks, BP Projects Number ( filled in accounting tab in BP projects) and in the query in Reference 1 column its giving the Invoice Numbers as posted in the Journal but for manual Journal Entries it not giving the Journal Number which I also want to be shown in Ref 1 or a seperat field.
    The Query is as under :
    select OCRD.cardcode 'Supplier Code',OCRD.cardname 'Name',sysdeb 'Debit Amount',syscred 'Credit Amount',
    case JDT1.transtype
    when '13' then 'INV'
    when '14' then 'AR CN'
    when '24' then 'INCOMING'
    else 'Other'
    end 'Type',
    Ref1,
    fccurrency 'BP Currency',
    CONVERT(VARCHAR(10), refdate, 103)'Posting Date' ,
    CONVERT(VARCHAR(10), duedate, 103) 'Due Date',
    CONVERT(VARCHAR(10), taxdate, 103) 'Doc Date' ,
    CASE
    when (DATEDIFF(dd,refdate,current_timestamp))+1 < 31
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "0-30 days",
    case when ((datediff(dd,refdate,current_timestamp))+1 > 30
    and (datediff(dd,refdate,current_timestamp))+1< 61)
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "31 to 60 days",
    case when ((datediff(dd,refdate,current_timestamp))+1 > 60
    and (datediff(dd,refdate,current_timestamp))+1< 91)
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "61 to 90 days",
    CASE
    when (DATEDIFF(dd,refdate,current_timestamp))+1 > 90
    then
    case
    when syscred= 0 then sysdeb
    when sysdeb= 0 then syscred * - 1
    end
    end "90 + days"
    from JDT1,OCRD where JDT1.shortname = OCRD.cardcode and cardtype = 'c' and intrnmatch = '0'
    ORDER BY OCRD.CARDCODE, taxdate
    Would appreciate if you can help me to get a solution in it.
    Regards,
    Kamlesh

    Dear Gordon,
    While executing the followings modified query it giving an error of
    Incorrect Syntax near the keyword 'to' and incorrect Syntax near 'Series'
    the query is as under :
    {select OCRD.cardcode 'Supplier Code',OCRD.cardname 'Name',sysdeb 'Debit Amount',syscred 'Credit Amount',
    case l.transtype
    when '13' then 'INV'
    when '14' then 'AR CN'
    when '24' then 'INCOMING'
    else 'Other'
    end 'Type',
    j.BaseRef'Trans #',
    case l.transtype
    when '13' then
    (Select Comments from OINV where OINV.Transid=j.Transid)
    else '-'
    end 'Inv.Rem.',
    (Select SeriesName From NNM1 Where Series=j.DocSeries and ObjectCode=l.TransType)'Series',
    to
    (Select Isnull(SeriesName, 'Manual') From NNM1 Where Series=j.DocSeries and ObjectCode=l.TransType)'Series',
    l.Ref1,
    fccurrency 'BP Currency',
    CONVERT(VARCHAR(10), l.refdate, 103)'Posting Date' ,
    CONVERT(VARCHAR(10), l.duedate, 103) 'Due Date',
    CONVERT(VARCHAR(10), l.taxdate, 103) 'Doc Date' ,
    CASE
    when (DATEDIFF(dd,l.refdate,current_timestamp))+1 < 31
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "0-30 days",
    case when ((datediff(dd,l.refdate,current_timestamp))+1 > 30
    and (datediff(dd,l.refdate,current_timestamp))+1< 61)
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "31 to 60 days",
    case when ((datediff(dd,l.refdate,current_timestamp))+1 > 60
    and (datediff(dd,l.refdate,current_timestamp))+1< 91)
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "61 to 90 days",
    CASE
    when (DATEDIFF(dd,l.refdate,current_timestamp))+1 > 90
    then
    case
    when syscred= 0 then sysdeb
    when sysdeb= 0 then syscred * - 1
    end
    end "90 + days"
    from JDT1 l
    Inner Join OJDT j On j.TransId=l.TransId
    ,OCRD where l.shortname = OCRD.cardcode and cardtype = 'c' and intrnmatch = '0'
    ORDER BY OCRD.CARDCODE, l.taxdate}
    Regards,
    Kamlesh

  • Query Help on RowNum

    Hi ,
    Please help me on this…
    Select * from EMP where Emp_Type in (1, 2 ) order by Emp_Type;
    the above query gives me the result like this
    Emp_Id Name Emp_Type
    100     asas     1
    101 dsds     1
    122     gfgf     1
    154     ytytyt     1
    125     uyuy     1
    153     reree     2
    154     ytytt     2
    600     trtrtr     2
    700 gfghf 2
    If I pass the Start with num 2 and give 3 as number of records to be displayed. I need to retrieve only the following rows..
    Emp_Id Name Emp_Type
    101 dsds     1
    122     gfgf     1
    154     ytytyt     1
    154     ytytt     2
    600     trtrtr     2
    700 gfghf 2
    If the Emp_Type was only one ie,
    Select * from EMP where Emp_Type in (1) order by Emp_Type;
    I know I can get it done by using TOP-N query method
    select * from
    (Select rownum RWnum ,A.* From
    (Select * from EMP where Emp_Type in (1) order by Emp_Type) A
    where rownum<=4)
    where RWnum>=2;
    but I am stuck up with doing for multiple Emp_Type..
    here the Emp_Type could be more than two values…
    Regards
    Ben Narendran

    Hi muthukumar S,dnikiforv,Vsugur
    Thanks a lot for the analytical function ROW_NUMBER().
    But still have some concern about the query you have given..
    Let me first run the inner query.
    SQL>
    SQL > Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
    EMP e where Emp_Type in (1, 2 ) order by Emp_Type;
    EMP_ID NAME EMP_TYPE RNO
    154 aaa 1 1
    101 dsds 1 2
    122 gfgf 1 3
    125 aaa 1 4
    100 asas 1 5
    700 gfghf 2 1
    600 trtrtr 2 2
    153 reree 2 3
    If I give the range from 2 and 3 am suppose to get the following rows.
    EMP_ID NAME EMP_TYPE RNO
    101 dsds 1 2
    122 gfgf 1 3
    600 trtrtr 2 2
    153 reree 2 3
    when I run the query you sent am getting the following result..
    SQL > select * from
    (Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
    EMP e where Emp_Type in (1, 2 ) order by Emp_Type)
    where rno between 2 and 3;
    EMP_ID NAME EMP_TYPE RNO
    101 dsds 1 2
    154 aaa 1 3
    600 trtrtr 2 2
    700 gfghf 2 3
    Here the company id 700 is not suppose to come, instead I have to get 153.
    So I made some changes in the view and , wrote it like this
    SQL> select * from
    (select rno Rwnum,Outer_Qry.* from
    (select Real_Qry.*,row_number() over(partition by emp_type order by emp_type)rno
    from
    (select emp_id,name,emp_type from emp where emp_type in (1,2) order by emp_type)Real_Qry)Outer_Qry
    where rno <=3)
    where Rwnum >=2;
    RWNUM EMP_ID NAME EMP_TYPE RNO
    2 101 dsds 1 2
    3 122 gfgf 1 3
    2 600 trtrtr 2 2
    3 153 reree 2 3
    I guess now am getting the correct result..
    Please correct me if I am wrong, and please let me know if I have to make any modification on it..
    Thanks and regards
    Ben

Maybe you are looking for

  • Hierarchy Level in report

    Hi GURUS, I have a requirement in report i.e. I need to display the Hierarchy level from the 4th level only, I do not want to see the first 3 levels, where do I do the settings for that in reporting. I was told that there can be some settings done in

  • Macbook and wireless printing...

    I recently bought a HP Photosmart C4580 Wireless Printer. It's hooked up to my I- MAC and working fine. Does anyone know how I can enable my macbook to send documents so I can print to it? Any help is greatly appreciated!!!!! Thanks!!!

  • How to use R.resource in Java from ANE?

    Hello,everyone,sorry for my poor English.. I want to ask "What is the appropriate way to manage resource in ANE"?? I have exported jar-library,and made ANE then called from Air Mobile. (I check include-resource-option when I export from eclipse.) Whe

  • Hyperlink not changing url to linked site

    I started a post on this before but spoke with Moniker.com and got a bunch of info. On my site www.jonbrownonline.com, the link to sweetasswebsite on the bottom works but the url stays "jonbrownonline.com". They explained that this is because jonbrow

  • NRM won't run after restart

    I was monitoring an oes2sp2 linux srvr with NRM (this is a vm on a xen kernal) when the cpu utilization went up to 100%. I discoverd that the httpstkd process was causing the high utilization. So I issued a restart using the rcnovell-httpstkd restart