Query For Max(amt_financed)

Hi Dears,
I want a select query for max of amount_financed for a particular customer
having same max(amount_financed) for more than one contracts. Also i want only one contract with max amount financed
Note :- one customer can have more than one contract
exm:
select distinct con_number,max(amount_finc) amt,customer from a
group by con_number,customer;
con_number amt customer
10 1000 a1
11 1000 a1
12 777 a1
13 250 a2
in above data i need only one record
i.e
con_number amt customer
10 1000 a1

10 1000 a1
11 1000 a1You get two contract numbers when for the maximum amount.
in above data i need only one record
10 1000 a1 Based on what condition you need only one record ??
Is this you wanted?
SQL> create table test (con_number number, amt number, customer varchar2(10));
Table created.
SQL> insert into test values(10, 1000, 'a1');
1 row created.
SQL> insert into test values(11, 1000, 'a1');
1 row created.
SQL> insert into test values(12, 777, 'a1');
1 row created.
SQL> insert into test values(13, 250, 'a2');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
CON_NUMBER        AMT CUSTOMER
        10       1000 a1
        11       1000 a1
        12        777 a1
        13        250 a2
SQL> select * from test
  2   where amt in (select max(amt) from test);
CON_NUMBER        AMT CUSTOMER
        10       1000 a1
        11       1000 a1

Similar Messages

  • SQL Query for max values!!

    Hi to all,
    I have four tables
    Tbl_one
    Tbl_two
    Tbl_three
    Tbl_four
    the relation between these tables is
    Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    I want a query like this
    Select tbl_one.com_name, tbl_three.test_date,tbl_four.order_date
    from Tbl_one,Tbl_two,Tbl_three,Tbl_four
    where Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    and tbl_three.test_date in (select max(test_date) from tbl_three)
    and tbl_four.order_date in select(max(order_date from tbl_for)
    and max(test_date)> Max(order_date)
    any way it is possible?
    the real problem is there are multiple test_dates and
    multiple order_date for same seq in tbl_one.seq.
    eg: -
    name (indian) which has three or more test_date and each test_date have more than one order_date
    indian (name) 01/01/2009(test_date) has ---- 01/10/2009, 01/20/2009 and 01/21/2009) order_dates
    india(name) 02/02/2009 (test_date) has ----- 02/10/2009, 02/20/2009 and 02/30/2009 (order_dates)
    india(name) 03/03/2009 test_date has ----- 03/10/2009, 03/20/2009 , 03/25/2009 (order_dates).
    japan has the same situation and so on
    what i wanted from the query is
    max(test_date)= 03/03/2009 > max(order_date)=03/25/2009
    ans: -
    name
    india(name) 03/03/2009 (test_date) 03/25/2009(order_date)
    etc. etc . etc.
    thanks!!
    Edited by: pl/sql baby on Mar 24, 2009 10:45 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:47 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:51 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:57 AM

    Please use tags either side of code / data (to preserve the formatting and spacing).
    I don't understand your requirement... 03/03/2009 is not greater than 03/25/2009 ?
    Could you please be clearer in your input/output samples and explain more about how to generate the output?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help in Query for max date

    Hi, How I can get the max(Gst_date) record of GRD. IF record of GRD has more than one record then I need the one max(GST_date) record of every GRD. Thanks.
    create table #CRT (CRT numeric, GRD numeric, GST_Date datetime)
    insert into #CRT values (7 ,1900,'01-01-2000')
    insert into #CRT values (19,1900,'01-01-2002')
    insert into #CRT values (24,1900,'01-01-2013')
    insert into #CRT values (7 ,2100,'01-01-2010')
    insert into #CRT values (19,2100,'01-01-2012')
    insert into #CRT values (7 ,2200,'01-01-2012')
    insert into #CRT values (19,2200,'02-02-2012')
    I would like the following output from query. The following record is the max(GST_Date ) of every '''GRD'".
    CRT   GRD   GST_Date
    24    1900  01-01-2013
    19    2100  01-01-2012
    19    2200  02-02-2012

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. Everything you posted is wrong. You should follow ISO-8601 rules for
    displaying temporal data. In fact is is required by ANSI/ISO Standards. You failed again. We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. You need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    Please, please learn why rows are not records. You do not even know what a key is or how to write a INTEGER NOT NULL(s, p) declaration. Allowing a table and column to have the same name is legal syntax and we regret not taking it out of the Standard. It is
    stupid! How can a set also be an attribute of itself? But your DDL gave no attribute  properties, as per ISO-11179. 
    Here is my attempt at repairs
    CREATE TABLE CRT 
    (crt_something INTEGER NOT NULL, 
     grd_something INTEGER NOT NULL, 
     PRIMARY KEY (crt_something, grd_something),
     gst_date DATE NOT NULL);
    Here is how we write an insertion statement; you are still using Sybase syntax! Why did you pick the most ambiguous, non-ANSI date display format? 
    INSERT INTO CRT 
    VALUES 
     ( 7, 1900, '2000-01-01), 
     ( 7, 2100, '2010-01-01'), 
     ( 7, 2200, '2012-01-01'), 
     (19, 1900, '2002-01-01'), 
     (19, 2100, '2012-01-01'), 
     (19, 2200, '2012-02-02'),
     (24, 1900, '2013-01-01');
    >> How I can get the MAX(gst_date) record [sic] of grd_something. If record [sic] of grd_something has more than one record [sic] then I need the one MAX(gst_date) record [sic] of every grd_something. <<
    WITH X
    (SELECT crt_something, grd_something, gst_date,
            MAX(gst_date) 
              OVER (PARTITION BY grd_something) AS gst_date_max
      FROM CRT)
     SELECT *
       FROM X
      WHERE gst_date_max = gst_date;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Query for MAX

    My Requirnment is :
    I need Sw_serial_number having follwoing things :
    1) Sw_serial_number having operation 1 and 3 between 23-02-11 to 06-06-2012 but no operation 6 has been performed between 23-02-11 to 06-06-2012 On these sw_Serial_numbers ,that i am checking in internal queries.
    2) Next in outer query i am checking the sw_serial_number having no operation 6 has been performed are having operation 6 between 07-07-2012 to 12-07-2012 .
    Problem:
    The Result also include the sw_serial_number which having operation 1 and 3 between 06-06-2012 to 06-07-2012 ,I want to exclude those sw_serial_number having operation 1 and 3 between 06-Jun to 06-July-2012 ,
    Please help me to achive this..Thanks in advance..
    SELECT sw_serial_number, remaining_trips, pass_price / 100, deposit / 100
    FROM op_accounting_unit
    WHERE operation_type_id IN ( 6 )
    AND sw_serial_number IN (SELECT DISTINCT( sw_serial_number )
    FROM (SELECT a.sw_serial_number
    FROM op_accounting_unit a
    WHERE a.operation_type_id IN ( 1, 3 )
    AND a.pass_id IN ( 54, 29, 61, 21, 27, 59, 24, 28, 60 )
    AND a.record_date BETWEEN To_date
    ( '02/23/2011 00:00:01', 'MM/DD/YYYY HH24:MI:SS')
    AND
    To_date( '06/06/2012 23:59:59', 'MM/DD/YYYY HH24:MI:SS')
    ORDER BY a.record_date)Main
    WHERE NOT EXISTS
    (SELECT c.sw_serial_number FROM op_accounting_unit c
    WHERE C.sw_serial_number = Main.sw_serial_number
    AND c.operation_type_id IN ( 6 )
    AND c.record_date BETWEEN To_date(
    '02/23/2011 00:00:01', 'MM/DD/YYYY HH24:MI:SS'
    ) AND To_date( '06/06/2012 23:59:59', 'MM/DD/YYYY HH24:MI:SS')
    AND c.station_id IN ( 1, 2, 3, 4, 5, 6 )))
    AND record_date BETWEEN To_date('07/07/2012 00:00:01', 'MM/DD/YYYY HH24:MI:SS')
    AND To_date( '07/12/2012 23:59:59', 'MM/DD/YYYY HH24:MI:SS')

    Like this
    SELECT y.sw_serial_number,
           y.remaining_trips,
           y.pass_price,
           y.deposi
      from (SELECT sw_serial_number,
                   remaining_trips,
                   pass_price / 100 pass_price,
                   deposit / 100 deposit
              FROM op_accounting_unit
             WHERE operation_type_id IN (6)
               AND record_date BETWEEN To_date('07/07/2012 00:00:01','MM/DD/YYYY HH24:MI:SS')
                                   AND To_date('07/12/2012 23:59:59','MM/DD/YYYY HH24:MI:SS')
           ) y,
           (select Main.sw_serial_number
              from (SELECT DISTINCT
                           sw_serial_number
                      FROM op_accounting_unit
                     WHERE operation_type_id IN (1,3)
                       AND pass_id IN (54,29,61,21,27,59,24,28,60)
                       AND record_date BETWEEN To_date('02/23/2011 00:00:01','MM/DD/YYYY HH24:MI:SS')
                                           AND To_date('06/06/2012 23:59:59','MM/DD/YYYY HH24:MI:SS')
                       and
                       not (operation_type_id IN (1,3) /* or maybe just (3) */
                       and  record_date BETWEEN To_date('06/07/2012 00:00:01','MM/DD/YYYY HH24:MI:SS')
                                            AND To_date('07/06/2012 23:59:59','MM/DD/YYYY HH24:MI:SS')
                   ) Main,
                   (SELECT DISTINCT
                           sw_serial_number
                      FROM op_accounting_unit
                     WHERE operation_type_id IN (6)
                       AND station_id IN (1,2,3,4,5,6)
                       AND record_date BETWEEN To_date('02/23/2011 00:00:01','MM/DD/YYYY HH24:MI:SS')
                                           AND To_date('06/06/2012 23:59:59','MM/DD/YYYY HH24:MI:SS')
                  ) x
            where Main.sw_serial_number = x.sw_serial_number(+)
              and x.sw_serial_number is null
           ) z
    where y.sw_serial_number = z.sw_serial_numberRegards
    Etbin

  • Query  for getting records  max  reported  timestamp and 2nd max report

    query for getting records in between
    max reported timestamp and 2nd max reported timestamp
    HERE IS ALL RESULT SET
    TIME DOMAIN
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    QUERY RESULT TO COME
    TIME DOMAIN
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    Message was edited by:
    user517983

    Hi,
    can we write query like this.
    1 select pd_user,PD_REPORTED_TIMESTAMP
    2 from sp_process_detail_current spdc
    3 where host_id='DSCP02469'and pd_user='TOMCAT'
    4 and exists(
    5 select PD_REPORTED_TIMESTAMP from sp_process_detail_current
    6* having max(PD_REPORTED_TIMESTAMP)-spdc.PD_REPORTED_TIMESTAMP=0)
    SQL> /
    PD_USER PD_REPORTED_TIMESTAM
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45

  • QUERY FOR CUSTOMERS FULL DEBIT AND CREDIT WITH CLOSING BALANCE

    Hi Friends,
       I need query for CUSTOMERS FULL DEBIT AND CREDIT WITH CLOSING BALANCE for selection criteria from date and to date.
       I know the Trial Balance Report will sort out this issue... but i need routeday wise report
    1. Business Partner Master Data - i created one UDF field called U_Routeday (MONDAY, TUESDAY, WEDNESDAY,THURSDAY,FRIDAY)
    2. The query should be like selection criteria 
                                  - Routeday [%0]
                                  - Posting Date [%1]                           
                                  - Posting Date [%2]
    CardCode
    Debit
    Credit
    Balance
    D10503
    25031.50
    24711.50
    2962.00
    D10641
    5466.00
    7460.00
    285.00
    D10642
    2866.00
    142.00
    give any helpful query ASAP... Thanks in advance

    Hi,
    Try this query:
    Declare
    @fromdate as datetime
    Declare
    @Todate as datetime
    Declare
    @Code as nvarchar(25)
    set
    @fromdate = ( select min(Ta.[RefDate]) from OJDT ta where
    Ta.[RefDate] >= [%0])
    set
    @Todate = ( select max(Tb.[RefDate]) from OJDT tb where Tb.[RefDate]
    <= [%1])
    set
    @code = (select max(Tc.[ShortName]) from JDT1 tC where Tc.[ShortName]
    = [%2])
    SELECT
    [Name] as AcctName, [Jan]= sum([1]), [Feb]= sum([2]), [Mar]=
    sum([3]), [Apr]= sum([4]),  [May]= sum([5]), [June]= sum([6]),
    [July]= sum([7]), [Aug]= sum([8]), [Sept]= sum([9]), [Oct]=
    sum([10]), [Nov]= sum([11]), [Dec]= sum([12]), total = sum
    (isnull([1],0)+ isnull([2],0) + isnull([3],0) + isnull([4],0) +
    isnull([5],0) + isnull([6],0) + isnull([7],0) + isnull([8],0) +
    isnull([9],0)+ isnull([10],0) + isnull([11],0) + isnull([12],0))
    from
    (SELECT
    T0.[ShortName] as Name, sum(T0.[Debit]-T0.[Credit]) as T,
    month(T2.[RefDate]) as month FROM JDT1 T0  INNER JOIN OACT T1 ON
    T0.Account = T1.AcctCode INNER JOIN OJDT T2 ON T0.TransId =
    T2.TransId WHERE T2.[RefDate] between @fromdate and @todate and
    T0.[ShortName]  = @code  GROUP BY T0.[ShortName],T2.[RefDate] ) S
    Pivot
    (sum(T)
    For  Month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    group
    by [Name],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]
    Let me know your result.
    Thanks & Regards,
    Nagarajan

  • Re:Query for Stock Statement for a particular item..!!!!

    Dear SAP Experts,
    I need a stock statement query  for a particular item which contains:
    1.ItemCode
    2.Item Description
    3.Item Price
    4.Opening
    5.Receipts
    6.Issues
    7.Closing
    8. Value
    The selection criteria are:
    1.Warehouse code
    2.Item Name
    3.Posting Date
    Plz give me a good solution for this issue.
    With Regards,
    Revathy

    Check this
    Declare @FromDate Datetime
    Declare @ToDate Datetime
    set @FromDate =
        (Select min(S0.Docdate) from OINM S0 where S0.Docdate >='[%0]')
    set @ToDate =
        (Select max(S1.Docdate) from OINM S1 where S1.Docdate <='[%1]')
    select * from
        SELECT T0.itemcode,
        min(T0.Dscription) as 'Item Description',
        min(B1.ItmsGrpNam) as 'Item Group', W1.Whscode, C1.Location,
        (isnull((
            Select sum(isnull(inqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode
            and O1.Warehouse=W1.Whscode
            and O1.docdate<@FromDate ),0)-
        isnull((
            Select sum(isnull(outqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode
            and O1.Warehouse=W1.Whscode
            and O1.docdate<@FromDate),0)
        ) as [Opening Stock],
        isnull((
            Select sum(isnull(inqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode
            and O1.Warehouse=W1.Whscode
            and O1.docdate>=@FromDate
            and O1.docdate<=@ToDate and O1.inqty>0
            and O1.transtype in (20,18)),0
        ) as [Purchase Quantity],
        isnull((
            Select sum(isnull(outqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
            and O1.docdate>=@FromDate and O1.docdate<=@ToDate
            and O1.outqty>0 and O1.transtype in (21,19)),0
        ) as [Purchase Return Quantity],
       isnull((
            Select sum(isnull(outqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
            and O1.docdate>=@FromDate and O1.docdate<=@ToDate and O1.outqty>0
            and O1.transtype in (13,15)),0
        ) as [sale Quatity],
        (isnull
            Select sum(isnull(inqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
            and O1.docdate<=@ToDate),0
            isnull((
                Select sum(isnull(outqty,0))
                from OINM O1
                where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
                and O1.docdate<=@ToDate),0)
        ) as [Closing Stock]
        FROM OINM T0
        INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
        INNER JOIN OITW T2 ON T1.ItemCode = T2.ItemCode
        INNER JOIN OITB B1 ON T1.ItmsGrpCod=B1.ItmsGrpCod
        INNER JOIN OWHS W1 ON T2.WhsCode = W1.WhsCode
        INNER JOIN OLCT C1 ON W1.Location=C1.Code
        Group by T1.itemcode, T0.Itemcode, W1.WhsCode, C1.Location
    ) a
    where (a.[Opening Stock]
            +a.[Purchase Quantity]
            + a.[Purchase Return Quantity]
            +a.[sale Quatity]+a.[Closing Stock]
           ) !=0
    Regards,
    Bala

  • Query for Opening Stock + Purchase Qty + Sales Qty

    Hi ,
    Can anyboday help me by how to develop a query for the following requirement. If any custom query is available please provide me .We are working on SBO 2007B PL 8. The required report structure is 
        ItemNo ***OpeningStock**** Purchase ********* Sales****
    (Batchwise)** Qty*** Value ****Qty** Value ***Qty***Value
    Thanks & Regards
    Srini

    Hi Srini,
    I found this on the forum, see if it helps you;
    select b.Itemcode,b.Item_Description,b.UOM, b.rate as Rate,b.Opening_Stock,b.Receipt,b.Issue, b.Material_Revalue,b.Closing_Stock,b.Closing_Value from (select *,(case closing_stock when 0 then 0 else(Closing_Value/Closing_Stock)end) as Rate from( SELECT T0.Itemcode as 'Itemcode' ,min(T0.Dscription) as 'Item_Description', max(T1.InvntryUom) as UOM, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,59,20,16,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0)+ (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0)))as Opening_Stock, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (20,18)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (67)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (58,59,16,14)),0)) as Receipt, (isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (13,15)),0) + isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (67)),0)+ isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (58,60,21,19)),0)) as Issue, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (162)),0) as Material_Revalue, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,59,20,16,14,19,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0))as Closing_Stock, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,18,-2,67,59,20,16,14,15,13,21,19,60,69,162)),0) as Closing_Value FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITW T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OITB B1 ON T1.ItmsGrpCod=B1.ItmsGrpCod where ((B1.ItmsGrpNam>='[%2]' and B1.ItmsGrpNam<='[%3]') or ('[%2]'='' and '[%3]'='')) GROUP BY T1.itemcode,T0.Itemcode )a Where (a.Opening_Stock + a.Receipt + a.Issue + a.Material_Revalue + a.Closing_Stock + a.Closing_Value) <> 0 )b 
    Thanks,
    Joseph

  • Query for non turn customer report in service module(Add-on)

    Hi,
    I want create  query for non turn customer report, that mean the customer who are not come for  last 6 months to our service workshop in service module(Add-on). this is a scenario. 
      SELECT T1.U_CardDate, T1.U_JCardNo,T1.U_TypeSrv,T2.U_VehReg,T2.U_PurchDt, T2.U_VehDesc, T2.U_VehModel, T1.U_KmsRead,   T1.U_BPCode, T0.CardName, T0.AddrType , T0.Building,T0.Block, T0.Address,T0.City,T0.ZipCode, T0.State1,T0.MailBuildi,T0.MailBlock, T0.MailAddres, T0.MailZipCod, T0.MailCity, T0.State2 ,T0.MailAddrTy,  T0.Phone1, T0.Phone2, T0.Cellular FROM [dbo].[OCRD]  T0 INNER JOIN [dbo].[@ALD_JOBCARD]  T1 ON T0.CardCode = T1.U_BPCode INNER JOIN  [dbo].[@ALD_VEHMAST]  T2 ON T1.U_BPCode = T2.U_BPCode WHERE T1.U_CardDate BETWEEN [%0] AND [%1] ORDER BY T1.U_CardDate.
    this query is get all  customer data who are not come to service workshop for last 6 month. i want to filter data who are not come last 6 months this year. kindly assist me
    thank you.

    Check this:
    SELECT Max(T1.U_CardDate) 'Lase Serve Date', T1.U_JCardNo,T1.U_TypeSrv,T2.U_VehReg,Max(T2.U_PurchDt) 'Last Purchase', T2.U_VehDesc, T2.U_VehModel, T1.U_KmsRead, T1.U_BPCode, T0.CardName, T0.AddrType, T0.Building,T0.Block, T0.Address,T0.City,T0.ZipCode, T0.State1,T0.MailBuildi,T0.MailBlock, T0.MailAddres, T0.MailZipCod, T0.MailCity, T0.State2 ,T0.MailAddrTy, T0.Phone1, T0.Phone2, T0.Cellular
    FROM [dbo].[OCRD] T0
    INNER JOIN [dbo].[@ALD_JOBCARD] T1 ON T0.CardCode = T1.U_BPCode
    INNER JOIN [dbo].[@ALD_VEHMAST] T2 ON T1.U_BPCode = T2.U_BPCode
    WHERE T1.U_BPCode NOT IN
    (SELECT DISTINCT U_BPCode FROM dbo.[@ALD_JOBCARD] WHERE DateDiff(DD,U_CardDate,GetDate()) < 183)
    Group By T1.U_JCardNo,T1.U_TypeSrv,T2.U_VehReg,T2.U_VehDesc, T2.U_VehModel, T1.U_KmsRead, T1.U_BPCode, T0.CardName, T0.AddrType, T0.Building,T0.Block, T0.Address,T0.City,T0.ZipCode, T0.State1,T0.MailBuildi,T0.MailBlock, T0.MailAddres, T0.MailZipCod, T0.MailCity, T0.State2 ,T0.MailAddrTy, T0.Phone1, T0.Phone2, T0.Cellular
    ORDER BY T1.U_CardDate

  • Trouble writing Query for Pivoting data from a table

    I am having a little trouble writing a query for converting the below table data into a pivot data. I am trying to write a query for which if I give a single valid report_week date as input it should give me the data for that week and also provide two extra columns, one which gives the data of last week for the same countries and the second column which gives the difference of numbers in both the columns(i.e. COUNT - COUNT_LAST_WEEK).
    REPORT_WEEK     DIVISION     COUNT
    9/26/2009     country1     81
    9/26/2009     country2     97
    9/26/2009     country3     12
    9/26/2009     country4     26
    9/26/2009     country5     101
    10/3/2009     country1     85
    10/3/2009     country2     98
    10/3/2009     country3     10
    10/3/2009     country4     24
    10/3/2009     country5     101
    10/10/2009     country1     84
    10/10/2009     country2     98
    10/10/2009     country3     10
    10/10/2009     country4     25
    10/10/2009     country5     102
    For example, if I give input as 10/10/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/10/2009     country1     84     85     -1
    10/10/2009     country2     98     98     0
    10/10/2009     country3     10     10     0
    10/10/2009     country4     25     24     1
    10/10/2009     country5     102     101     1
    For example, if I give input as 10/3/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/3/2009     country1     85     81     4
    10/3/2009     country2     98     97     1
    10/3/2009     country3     10     12     -2
    10/3/2009     country4     24     26     -2
    10/3/2009     country5     101     101     0
    Can anyone please shed some light on Query building for the above scenarios.
    Thank you
    SKP
    Edited by: user11343284 on Oct 10, 2009 7:53 AM
    Edited by: user11343284 on Oct 10, 2009 8:28 AM

    I assume there is no gap in report weeks. If so:
    SQL> variable report_week varchar2(10)
    SQL> exec :report_week := '10/10/2009'
    PL/SQL procedure successfully completed.
    with t as (
               select to_date('9/26/2009','mm/dd/yyyy') report_week,'country1' division,81 cnt from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country2',97 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country3',12 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country4',26 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country1',85 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country4',24 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country1',84 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country4',25 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country5',102 from dual
    select  max(report_week) report_week,
            division,
            max(cnt) keep(dense_rank last order by report_week) cnt_this_week,
            max(cnt) keep(dense_rank first order by report_week) cnt_last_week,
            max(cnt) keep(dense_rank last order by report_week) - max(cnt) keep(dense_rank first order by report_week) difference
      from  t
      where report_week in (to_date(:report_week,'mm/dd/yyyy'),to_date(:report_week,'mm/dd/yyyy') - 7)
      group by division
      order by division
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    10-OCT-09 country1            84            85         -1
    10-OCT-09 country2            98            98          0
    10-OCT-09 country3            10            10          0
    10-OCT-09 country4            25            24          1
    10-OCT-09 country5           102           101          1
    SQL> exec :report_week := '10/3/2009'
    PL/SQL procedure successfully completed.
    SQL> /
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    03-OCT-09 country1            85            81          4
    03-OCT-09 country2            98            97          1
    03-OCT-09 country3            10            12         -2
    03-OCT-09 country4            24            26         -2
    03-OCT-09 country5           101           101          0
    SQL> SY.

  • Query for Identifying column changes

    Hi Guys,
    Need help in getting a query for my scenario.
    I have 2 table Table A and Table B. Both have same columns and data type.
    Table A:
    Id  PersonId    Name      Code      Date
    1    1000           John         M         2014-07-28
    2    1001           Mary         B         2014-07-28
    3    1002           Robin        R         2014-07-28
    4    1003           Maxie        N         2014-07-28
    Table B:
    Id  PersonId    Name      Code      Date
    1    1000           John                     2014-07-28
    2    1001           Hary         S         2014-07-28
    3    1002           Justin       Q         2012-07-28
    4    1003           Maxie       P         2013-07-28
    My situation is:
    I need to compare both the tables and need to identify the rows that has a change in all columns, if all other columns are not changed and Code is changed to blank, i need to ignore that row.
    The expected outcome is:
    Id  PersonId    Name      Code      Date
    2    1001           Hary         S         2014-07-28
    3    1002           Justin       Q         2012-07-28
    4    1003           Maxie       P         2013-07-28
    Thanks Guys...

    I found the solution in a easy way i guess...
    select * from 
    SELECT ID, PERSONID,NAME,
    case when code is null then
        select a.code from tablea A where A.ID = B.ID
    else
     a.code
    end as Code,
    DATE FROM TABLE B
    MINUS
    SELECT ID,PERSONID,NAME,CODE,DATE FROM TABLE A
    What do you guys think...would it work for my scenario....
    i am testing few scenarios looks like working.......

  • Query for Number generation

    hi all,
           Does anyone have an Query which i can use for generating an automatic generation of Number in sales order.
    Suppose whenever sales order add it generate no. serially like 01,02,03........... and so on in UDF.
    thanks and regards
    rahul

    Hi Rahul..
    The number in sales order is already automatic. If you want to have an UDF whit another numeration, different from the default series, you must create a  query that select the max numeration +1 from UDF.
    E.g.
    The query:
    Select max(UDF_field)+1 from UDF_field
    Let me know if is the right solution

  • Tabular DAX Query for MINX, MAXX and AVGX

    Hi,
    I need to create three measure to get value of min, max and avg.
    For example, I have 3 columns in my table. I need to take minimum value of Column3 based on column2. If column2 value is 0, then we have to consider entire table data else only we have to consider
    Column1 Column2 Column3
    AAA         1      150
    BBB         1       50
    CCC         0       25
    DDD        1        40
    EEEE        0        70
    I need to take minimum,maximun and avg value of Column3 based on column2. If column2 value is 0, then we have to consider entire table data. IF column2 value is 1, then only we have to consider the row of column2=1.
    I expect the result as like below. Can you please help to find the DAX query for the measure.
    Column1 Column2 Column3  MinValue
    AAA         1      150            40
    BBB         1       50             40
    CCC         0       25             25
    DDD        1        40             40
    EEE         0         70            25
    EEE         0         70

    Hi,
    I have 3 columns in my table. I need to take minimum value of Column3 based on column2. If column2 value is 0, then i have to consider entire table data else only i have take minimum(column3) by considering rows of column2=1.
    Column1 Column2 Column3
    AAA         1      150
    BBB         1       50
    CCC         0       25
    DDD        1        40
    EEEE        0        70
    Try1:
    Min:=IF(Column2>0,MINX(FILTER(table,[column2]>0),[column3]),Min(Column3))
    Try2:
    Min:=MINX(IF(Column2>0,FILTER(table,[column2]>0),table),[column3]))
    Try3:
    Created Measure called Min1.
    Min1:=MINX(FILTER(Table,[Column2]>0),[Column3])
    And then i made this min1 measure to be hidden.
    Created another measure called Min2.
    Min2:=IF(ISBLANK([Min1]),MIN([column3]),[Min1])
    Both DAX query is not working. Can anyone help to have the correct DAX query to create Min measure based on the conditions.

  • Sbt__rpc_cat_query: Query for piece 1ujb3oqb_1_1 failed

    Hi,
    Currently I'm trying to run Oracle database backup using EM database control and OSB. I have configure library and tape drive in OSB and also created new job in EM to backup the database. But when I run the job it end up with the following error message.
    If anyone encounter the same problem? and you know the solution. Please let me know in detail.
    RMAN-00571:
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
    RMAN-00571:
    RMAN-03009: failure of backup command on oem_sbt_backup channel at 03/12/2008 19:11:12
    ORA-19506: failed to create sequential file, name="1ujb3oqb_1_1", parms=""
    ORA-27028: skgfqcre: sbtbackup returned error
    ORA-19511: Error received from media manager layer, error text:
    sbt__rpc_cat_query: Query for piece 1ujb3oqb_1_1 failed.
    I really need help from you guy's.
    Thanks,
    Bala

    Thanks. But I don't think that is the issue. I've compared the values on this server with the values on my other servers that are running OSB client successfully and they are comparible.
    Rich
    oracle@vlx1032 /ora01/oracle > grep ^[^#] /etc/sysctl.conf
    net.ipv4.ip_forward = 0
    net.ipv4.conf.default.rp_filter = 1
    net.ipv4.conf.default.accept_source_route = 0
    kernel.sysrq = 0
    kernel.core_uses_pid = 1
    kernel.shmmax = 8589934592
    kernel.shmall = 16777216
    kernel.msgmnb = 65536
    kernel.msgmni = 256
    kernel.sem = 300 32000 100 1024
    fs.file-max = 131072
    net.ipv4.ip_local_port_range = 1024 65000
    net.core.rmem_default = 1048576
    net.core.wmem_default = 1048576
    net.core.rmem_max = 1048576
    net.core.wmem_max = 1048576

  • Re:Query For Inventory Transfer..!!!

    Dear Members,
    My Scenario is,
    I want to take a report for inventory transfer that contains
    1. Itemcode
    2.Item description
    3.quantity
    4.inventory quantity on the previous day.
    I have taken the tables owtr,wtr1,oitm and oitw.But the issue is if my document date is like 30.11.2010 i want the inventory quantity value as  on 29.11.2010.
    I need only query not SAP Reports.Plz suggest a suitable query for this issue.
    With Regards,
    Revathy

    Hi Revathy,
    You have to use OINM table to get your desired Stock on past dates.
    Have a look at these queries.
    1. Stock per itemwise
    select t1.ItemCode,max(t1.dscription) [Name],(sum(isnull(t1.InQty,0)) - sum(isnull(t1.OutQty,0)) ) [ClsStock],(sum(t1.transvalue)) [ClsValue]
    from OINM t1
    where  t1.DocDate <= '[%1]'
    group by
    t1.ItemCode
    2.Stock per item per warehouse wise
    select t1.ItemCode,max(t1.dscription) [Name],t1.warehouse [Warehouse],
    (select whsname from owhs o1 where ((o1.whscode) = (t1.warehouse))) [WarehouseName],
    (sum(isnull(t1.InQty,0)) - sum(isnull(t1.OutQty,0)) ) [ClsStock],(sum(t1.transvalue)) [ClsValue]
    from OINM t1
    where t1.DocDate <= '[%1]'
    group by
    t1.ItemCode,t1.warehouse
    Regards,
    Bala
    Edited by: Balakumar Viswanathan on Dec 10, 2010 5:22 PM

Maybe you are looking for

  • .flv converter for Mac OSX

    Does anyone know where I can find a program to convert .flv files to AVIs or MPEGs? Freeware, preferably.

  • HT5051 Ok... So today, when I try to save a spreadsheet from Numbers, iCloud is not an option. Now What?

    iCloud seems the only vehicle for sharing spreadsheets, yet current version of numbers doesn't offer that as an option. Is there a workaround?

  • Time in graph

    Hi, I have a keyfigures which is type Time (HH:MM:SS) in char6 When i display it in my table it looks like 07:15:34. But when i display it in a graph it is displayed concatenated with todays date. Like today it would look like 20070730071534. This ma

  • I am having problems opening drop down boxes

    i have photoshop elements 11 and have been having trouble with opening some of the drop down boxes, also i purchased the photoshop elements 11 book for some help but that seems to be different to the virson for photoshop is thatfor mac, i have window

  • How to tell what generation ipod you have

    Is there a way to tell what generation ipod you have? I have a 2 GB ipod Nano and I want to buy a CD player that also plays music from your ipod, but it only supports 2nd generation and up.