Query help again

Hi all,
I have a table as given below:
NO NAME SAL
1 x 200
1 a 100
2 y 400
2 b 300
I want to query in such a way that the result should be as follows:
NO NAME SAL
1
x 200
a 100
2
y 400
b 300
How to write this...thanks iin advance...

Hi,
880186 wrote:
no name sal1
x 200
a 100
2   y 400 b 300
Does this looks good now?
No. Does it look good to you?
Use one \ tag before the first line of each formatted section, and another at the end of the section.  You don't need separate tags on every line.
This query, using the scott.emp table, shows one way to do what you want:SELECT     CASE
          WHEN GROUPING (ename) = 1
          THEN job
     END     AS job
,     ename
,     sal
FROM     scott.emp
GROUP BY GROUPING SETS ( (job, ename, sal)
               , (job)
ORDER BY emp.job
,      ename          NULLS FIRST
,     sal
This assumes that the combination (job, ename, sal) is unique.
Output:JOB ENAME SAL
ANALYST
FORD 3000
SCOTT 3000
CLERK
ADAMS 1100
JAMES 950
MILLER 1300
SMITH 800
MANAGER
BLAKE 2850
CLARK 2450
JONES 2975
PRESIDENT
KING 5000
SALESMAN
ALLEN 1600
MARTIN 1250
TURNER 1500
WARD 1250

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 :-(

  • News "FLASH"... Nancy O (the legend) ... i need help again

    I am trying to put a banner on my website for my exam.... It will have to have an image with logos flashing across and stopping for a few seconds before carrying on.and out the other side.  I have looked up everywhere to see how this is done but with no joy. There is lots of info out there but it is not working for me.  In Flash i have no problem creating a banner image with various logos moving  from one side to the other or even changing the image from one shape to another or bouncing it up and down the stage from one side to the other. I can even stagger the timelines for the logos to make them enter one after the other. The one thing i can not get to grips with is making the images stop or pause after they have entered from one side before exiting  the other side. I have followed step by step many  youtube tutorials but the authors are wizzing through them too fast and despite folling every step second by second, i  am missing a vital step somewhere.   Would someone please let me know step by  step (and please assume i am an idiot when doing this) the sequence i must follow from the very begining to the last step when i publish.

    Noooooooo........ When i saw your email notification i had high hopes of getting the answer i have been trying to work out for two days....but no problem ..your still a legend ha ha ... you got me out of a big hole in this project the last time... but thanks for taking the time to reply, i will try the other forum.
    Date: Thu, 26 Jan 2012 17:28:18 -0700
    From: [email protected]
    To: [email protected]
    Subject: News "FLASH"... Nancy O (the legend) ... i need help again
    Re: News "FLASH"... Nancy O (the legend) ... i need help again created by Nancy O. in Dreamweaver - View the full discussion
    You'll get better answers in the Flash Forums for whichever Action Script ver you're using.
    Sorry.  I don't do much Flashy stuff anymore.  As far as I'm concerned, when Apple iDevices quit supporting Flash, it became a dying web technology.  
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4167793#4167793
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4167793#4167793. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Dreamweaver by email or at Adobe Forums
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Help (again) with Average Script

    Hi Everyone:
    I have problems again with a script in calculation manager:
    I need to calculate the average of a member in one account across the year. For example, for Jan the average of Count_1 is equal to the value of Count_2 in Jan; for Feb Count_1 is equal to the sum of values of Jan and Feb from Count_2 divided for 2; for Mar Count_1 is equal to the sum of values of Jan, Feb and Mar from Count_2 divided for 3 and so on.
    I'm using the follow script:
    *"Count_1"=@AVGRANGE(SKIPNONE,"Count_2",@CURRMBRRANGE("YearTotal",LEV,0, ,0));*
    But this script is averaging bad, because what it does for January is to take the January value and divide by two, to sum the values in February January and February and divide by 3, to sum the values in March, January, February and March and divided by 4 and so on.
    How i can solve this problem and make a script that works?
    Thanks for your help again.

    Please, someone can help me???

  • Need Help again...

    Hi all...
    Really need help again this time...
    I am trying to do a web page and thought of placing 4 video
    clips into
    1 Loader...viewers can simply choose any of the videos they
    would like
    to watch...and all the video clips will then play in the same
    Loader on
    the exact X & Y values...Is it possible?
    eg. 4 Buttons with linking to 4 different video clips.
    When a video clip selected, play in a Loader of X and Y
    values.
    When another clip selected, play in the same Loader.
    Moca or anyone...please help me a.s.a.p...Thanks in
    advance...

    Does this happen to a wired computer or to a wireless computer? If it happens to a wireless computer ONLY but not to a wired computer, a firmware upgrade might not be necessary at all.
    Make sure your wireless settings are personalized, try using channel 11 and when you go to advanced wireless settings, try setting the beacon interval to 50 instead of 100.
    On how to do the things mentioned in the 2nd paragraph, open up IE and type on the address bar the numbers 192.168.1.1 (username leave it blank, password as a default is admin). Go the the Wireless tab.

  • Again same problem error 0xE8000003 pls help again i don't know it keep doing that

    Again same problem error 0xE8000003 pls help again i don't know it keep doing that please help with that

    Hello sartip fatah,
    The following article provides further information regarding this error, and steps to help resolve it.
    iOS: Unknown error containing '0xE' when connecting to a Windows PC
    http://support.apple.com/kb/TS3221
    Cheers,
    Allen

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Re: help again please

    Check your braces for your 'if' statements. I don't think they are what you intended. You only update carmake if the car is a mercedes.
    Please use more descriptive subject titles. "Help again please", "help appreciated", and "just cant work this out" could describe 99% of the threads on this forum. Maybe something like "Why is this an infinite loop?" would be useful.

    import java.io.*;
    import java.util.*;
    public class TestPlan
       public static void main(String args[])throws FileNotFoundException
          Scanner inFile = new Scanner(new FileReader("c:\\praccc.txt"));
          PrintWriter outFile = new PrintWriter("c:\\cars.out.txt");
          String carMake = inFile.next();
          outFile.println("Enter make [* ends]:> " + carMake);
          int age = inFile.nextInt();
          outFile.println("Enter age:> " + age);
          int daysHired = inFile.nextInt();
          outFile.println("Enter no. of days hired:> " + daysHired);
          int kmsTravelled = inFile.nextInt();
          outFile.println("Enter kms travelled:> " + kmsTravelled);
          while(!carMake.equals("*"))
                carMake = inFile.next();
                outFile.println("Enter make [* ends]:> " + carMake);
                age = inFile.nextInt();
                outFile.println("Enter age:> " + age);
                daysHired = inFile.nextInt();
                outFile.println("Enter no. of days hired:> " + daysHired);
                kmsTravelled = inFile.nextInt();
                outFile.println("Enter kms travelled:> " + kmsTravelled);
                inFile.close();
                outFile.close();
    }ok sorry im not very experienced with java as you can tell but if this question doesnt solve my prob I think I will give up. The code above which i have broke up still gives me NoSuchElementException. The file praccc.txt simply contains....
    mercedes 10 100 100
    mercedes 20 200 200
    mercedes 30 100 200
    mercedes 30 200 100
    mercedes 20 130 200
    *

  • SQL query....need help again

    Actor (Aname: varchar(40), Ano: varchar(6)) Ano is pk
    Movie (Mname: varchar(40),mno: varchar(8)) Mno is pk
    PlayIn (Ano, Mno, Pay: Integer) Ano and Mno are fk referencing Acotr and Movie respectively.
    Actor(Aname, Ano)
    A Bingo, A1
    B Castro, A2
    C Katie, A3
    S Hommy, A4
    J Tammy, A5
    K loren, A6
    Movie(Mname, Mno)
    Gladiator, M1
    Cast, M2
    Dog, M3
    Jilters, M4
    PlayIn(Ano,Mno,Pay)
    A1 M1 800
    A1 M2 1500
    A2 M2 78
    A2 M3 1750
    A2 M4 2301
    A3 M2 904
    A3 M3 629
    A4 M2 565
    A4 M3 5695
    A4 M4 1255
    A5 M1 989
    A5 M4 238
    A6 M2 137
    A6 M3 236
    A6 M4 545
    write a query for this QUESTION:
    for each movie, list the movie number, the average pay and the total number of actors in the movie.....

    hi - didn't you read my response to your other nearly identical thread?
    SQL query...pls help ASAP
    may I suggest you get a basic book on oracle SQL and immerse yourself for a few hours before comming to this forum for answers to your homework questions?

  • Help again to write a query

    hello
    I hvae made the following query to see goods receipt - purchase order and goods return
    It seems ok but I have several times the same records per line I wonder what triggers the number of record per let's say DocNum from OPDN. I would like to see only one record per DucNum OPDN.... Thank you if you find the problem
    SELECT T2.[DocNum] as 'N° cde', T2.[DocDate], T2.[DocStatus], T1.[DocNum] as 'N° Entrée Mses', T1.[DocDate],T1.[DocStatus], (T1.DocTotal-T1.VATsum-T1.TotalExpns) AS 'Valeur Entrée Mses', T1.[Weight], T3.[DocNum] as 'N° Retour', T3.[DocDate], T3.[DocStatus], (T3.DocTotal-T3.VATsum-T3.TotalExpns) AS 'Valeur Retour Mses', T3.[Weight] FROM PDN1 T0 
    INNER JOIN OPDN T1 ON T0.DocEntry = T1.DocEntry
    inner join OPOR T2 ON T0.BaseRef=T2.[DocNum]
    LEFT OUTER JOIN RPD1 T4 ON T4.BaseRef=T1.[DocNum]
    LEFT OUTER JOIN ORPD T3 ON T4.DocEntry = T3.DocEntry
    WHERE T1.DOCDATE>=[%0] AND T1.DOCDATE<=[%1]

    Hi G Delanoe
    This is happening based on the number of line items in the Purchase Order & Goods Receipt PO. You will need to use a group by on some of the fields, such as the document numbers, to display each document only once.
    Try the following and see if it does the job.
    SELECT T2.DocNum as 'N° cde', T2.DocDate, T2.DocStatus, T1.DocNum as 'N° Entrée Mses', T1.DocDate,T1.DocStatus, AVG(T1.DocTotal-T1.VATsum-T1.TotalExpns) AS 'Valeur Entrée Mses', AVG(T1.Weight), T3.DocNum as 'N° Retour', T3.DocDate, T3.DocStatus, AVG(T3.DocTotal-T3.VATsum-T3.TotalExpns) AS 'Valeur Retour Mses', AVG(T3.Weight )
    FROM PDN1 T0 INNER JOIN OPDN T1 ON T0.DocEntry = T1.DocEntry inner join OPOR T2 ON T0.BaseRef=T2.DocNum LEFT OUTER JOIN RPD1 T4 ON T4.BaseRef=T1.DocNum LEFT OUTER JOIN ORPD T3 ON T4.DocEntry = T3.DocEntry
    WHERE T1.DOCDATE>= '[%0]' AND T1.DOCDATE<= '[%1]'
    GROUP BY T2.DocNum, T2.DocDate, T2.DocStatus, T1.DocNum, T1.DocDate, T1.DocStatus, T3.DocNum, T3.DocDate, T3.DocStatus
    Kind regards
    Peter Juby

  • Plsql/sql iterative delete query help

    I need some help.....I have 4 tables joined by TRANSACTION_ID
    TRANSACTIONS Table
    TRANSACTION_ID NUMBER(20)
    USER_ID NUMBER(20)
    EXPIRY TIMESTAMP
    TX_ATTEMPTS Table
    TX_ATTEMPT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    TX_ELEMENTS
    TX_ELEMENT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    CIDENT
    CIDENT_ID NUMBER(20)
    Each TRANSACTION has an associated
    USER_ID - ID identitying a unique person
    EXPIRY - Timestamp to indicate when the TRANSACTION expires in the system.
    A USER_ID can have many TRANSACTIONS associated with it.
    I'm looking for some PL/SQL that will accept a variable (RETAIN_NUM) indicating the number of most recent transactions that need to be retained for all users in the database.
    For example if the RETAIN_NUM is 5, the sql should do the following:
    1) Retain the 5 most recent transactions in the TRANSACTIONS table for each USER_ID (including associated entries in the other 3 tables also). All older entries for each USER_ID should be deleted from the TRANSACTIONS table (including any associated entries in the other 3 tables also).
    2) Before deleting the data in all the tables I want to export it, ideally using expdp in a single execution.
    Is there anyone that could please help me with either part of this??
    Edited by: user12213281 on Jun 4, 2013 3:47 PM

    Thanks for your comments. The way the system works is complicated and I'm not sure how to tackle the overall delete...that is why I have asked for some help.
    I have examined the schema structure again and have identified some useful points to make it easier.
    Each of the tables have several other columns but I had stripped them down for the purpose of making this query easier to understand. Luckily each of the tables in the schema do have a CIDENT_ID column with a cascade delete constraint from the CIDENT table. This works most simply for the TX_ELEMENTS table so I don't think I will need to include that table specifically in any delete. Unfortunately at this time I am not able to create any other new relationships between the tables.
    The tables involved now are:
    TRANSACTIONS Table
    CIDENT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    USER_ID NUMBER(20)
    EXPIRY TIMESTAMP
    TX_ATTEMPTS Table
    CIDENT_ID NUMBER(20)
    TX_ATTEMPT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    CIDENT Table
    CIDENT_ID NUMBER(20)
    The difficulty comes with the TRANSACTIONS and TX_ATTEMPTS tables.
    Each TRANSACTIONS and TX_ATTEMPTS entry has a completely separate CIDENT entry. What I was thinking I need to do is:
    1) Generate a list of TRANSACTION_IDs and corresponding CIDENT_IDs from the TRANSACTIONS table that are the most recent "retain_num" entries for each USER_ID (using EXPIRY_DTM).
    2) Then generate a list of CIDENT_IDs from the TX_ATTEMPTS table based on the TRANSACTION_IDs from 1) above
    3) Delete the CIDENT entries using the CIDENT_IDs obtained from 1) and 2) above.
    These individually may not be so bad but I don't know how to combine them....
    Any pointers would really be greatly appreciated...

  • Formula in Query: New--Again

    Hello,
    Please refer to link:
    Formula in query
    please guide me as to how to handle the input date & the date difference?
    thanks,
    (posting it again as i am not able to assign points from the old post!!)

    Hi,
    Define a variable with ready for input option so that it during the runtime variable will ask for the inputs.
    hope this will be helpful.
    Vijay

  • I need sql query help

    I have 5 tables.i want to select one respective record from 5 table .But i will pass only one argument...
    what is the query for that..................

    I didn't understand that that's why i made it
    again.If you ask a question and you don't understand the answer, then you should ask for an explanation of the answer.
    If you get an explanation and you still don't understand, then maybe that is an indication that you don't have enough knowledge of the basics. In this case, perhaps you should try to read a book on SQL and relational database theory.
    Myself only asked that question also.
    Now also i am asking u r able to solve this question
    or not.As I said, I will read the other thread (where you have started to get help) and if I have anything to add, I will post there.

  • 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

Maybe you are looking for