Selection of records based on minimum date actioned

Post Author: jrdoyle
CA Forum: Data Connectivity and SQL
Hi!
I've been building a report that displays records, grouped by the Service Department  to which they have been assigned; however I need to constrain the report to only show the Service Department to which the record was first assigned.  I had tried to group the report by incident reference #, and had in the details the actions taken agains the record, the date of the action, the SVD to which it was assigned, etc.  In the Select Expert, I have the following:
{INC_DATA.EVENT_TYPE} = "i" and{SERV_DEPT.SERV_DEPT_SC} = "DISPATCH" and{INCIDENT.DATE_LOGGED} in DateTime (2007, 05, 01, 00, 00, 00) to DateTime (2007, 05, 30, 00, 00, 00) and{SERV_DEPT_1.SERV_DEPT_SC} in ["CUSTHOME", "CUSTWEST", "HARDWARE"]
The SERV_DEPT_1 table will displays the information about the Service Department to which the records are assigned.  I need to be able to count only the minimum date of assignment.  I've tried using the Minimum function, but it appears that I then can't summarize (count records) higher up in the report groups, as it gets evaluated after (?) the groups are made.
Is anyone able to offer suggestions as to how I might go about this?  I have tried to somehow flag records in the details which meet the criteria, but haven't been able to come up with anything yet.
Thanks!

Post Author: Jagan
CA Forum: Data Connectivity and SQL
I'm not quite sure how/where you tried to use the Minimum function - sounds like you used it in the record selection formula? Anyway, if you want the report to have only the earliest record per service department group then you can use the group selection expert, e.g.{incident.date_logged} = minimum({incident.date_logged}, {serv_dept_1.serv_dept_sc})If you want to display the earliest record but still have the other records there for processing then sort on {incident.date_logged} ascending, suppress the details, and print in the {serv_dept_1.serv_dept_sc} group header. i.e the record you're "looking" at in the group header is the first one for the group.The difference between the two is that the former will only have one record per service department group (assuming the date_logged is unique per incident per department) while the latter will have all records but only display one. This makes a difference when using the built-in summary functions.

Similar Messages

  • Create a record based on From date and To Date in CRM 2015 Plugins

    Hi all
    in my account screen i have two date field from date and Todate and i have one child entity member when i am creating a
    new account then based on from date and to date number of child record should be created
    for example in account screen
    if from date=2/1/2015 and 
       To date=31/03/2015
    then number of child record should be created
    in this manner 
    from date      to date 
    2/1/2015       31/01/2015
    01/02/2015     28/02/2015
    1/03/2015      31/03/2015

    Hi,
    OK. It seems you want to create 3 records (custom child entity) where the first has the same From Date as the Account and goes up to the end of the month, and the other records go from there.
    This logic can be implemented via a Plugin that could run on the create and update of these fields on Accounts. From the Plugin, you can set up the logic and fill the records with the necessary information.

  • Getting the last set of records based on a Date Field

    Hi All
    i have the followings data set in a table
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970150                      129700104071     64260                        8/6/2002
    970150                      229700101893     64261                        8/6/2002
    970150                     149700101893     64262                        8/6/2002
    970150                       97015011     79252                        9/19/2005
    970150                       97015023     79255                        9/19/2005
    970150                       97015013     79253                         9/19/2005
    970150                       97015021     79254                        9/19/2005
    970040                      129900105213     56155                         9/26/2000
    970040                                 1101     29841                        6/9/1998
    970040                       97004023     143349                        10/28/2008
    970040                              2101     29842                        6/9/1998
    970040                        97004021     143348                        10/28/2008
    970040                       97004011     143346                        10/28/2008
    970040                      149700101903     64196                       7/16/2002
    970040                              2301     29844                      6/9/1998
    970040                         97004013     143347                         10/28/2008
    970040                                  1301       29843                        6/9/1998I need to get only those records with the latest date and i'm using the following query
    SELECT t.track_id_grp, t.track_id_nbr, t.track_sample_id,
           MAX (t.start_date) OVER (PARTITION BY t.track_id_grp) AS start_date
      FROM track_table t
    WHERE t.track_id_grp IN ('970150', '970040')And i'm getting the following dataset
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970040                      1.299E+11     56155     10/28/2008
    970040                      1101                     29841     10/28/2008
    970040                      97004023                     143349     10/28/2008
    970040                      2101                     29842     10/28/2008
    970040                      97004021                     143348     10/28/2008
    970040                      97004011                     143346     10/28/2008
    970040                      1.497E+11     64196     10/28/2008
    970040                      2301                     29844     10/28/2008
    970040                      97004013                     143347     10/28/2008
    970040                      1301                     29843     10/28/2008
    970150                      1.297E+11     64260     9/19/2005
    970150                      97015011                     79252     9/19/2005
    970150                      97015021                     79254     9/19/2005
    970150                      2.297E+11     64261     9/19/2005
    970150                      97015013                     79253     9/19/2005
    970150                      97015023                     79255     9/19/2005
    970150                      149700101903     64262     9/19/2005And i was expecting the following dataset
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970150                      97015011                             79252     9/19/2005
    970150                      97015023                             79255     9/19/2005
    970150                      97015013                             79253     9/19/2005
    970150                      97015021                             79254     9/19/2005
    970040                      97004023                             143349     10/28/2008
    970040                      97004021                             143348     10/28/2008
    970040                      97004011                             143346     10/28/2008
    970040                      97004013                             143347     10/28/2008I was expecting to get only those records with the latest date, instead i'm getting all the records with the max date in it, please need help or advice.
    Thanks

    Try this -
    SELECT track_id_grp, track_id_nbr, track_sample_id, start_date
      FROM (SELECT t.track_id_grp, t.track_id_nbr, t.track_sample_id,
                   t.start_date,
                   ROW_NUMBER () OVER (PARTITION BY t.track_id_grp, t.track_sample_id ORDER BY t.start_date DESC)
                                                                            AS rn
              FROM track_table t
             WHERE t.track_id_grp IN ('970150', '970040'))
    WHERE rn = 1let me know if that works.
    Edited by: Sri on Apr 28, 2011 9:24 AM

  • Select records based on max(date)

    Hi everyone,
    I have a table (tbl_training) with training information-such as who took what training, when they took it, scores they received and other various stuff.
    In this table, a person could have taken multiple training within the year. what i need to see in my results is, the last training the person took. I assume i am looking to query something that produces max(date_of_training) and maybe grouping my id_number. I have tried various combinations of sub-queries to no avail. Any help is welcomed.
    So my data may look something like this:
    id_number date_of_training score last_name first_name instructor rank
    1234 01/01/09 50 doe john mr. hank sgt
    1234 02/13/09 72 doe john mr. hank sgt
    1234 01/31/09 60 doe john mr. hank sgt
    5678 02/03/09 80 smith lisa mr. hank cpl
    What i need returned in the query is:
    1234 02/13/09 72 doe john mr. hank sgt
    5678 02/03/09 80 smith lisa mr. hank cpl
    Select id_number, date_of_training, score, last_name, first_name, instructor, rank
    from tbl_training;
    Thanks for the help in advance.

    Try this code
    select * from (
    Select id_number, date_of_training, score, last_name, first_name, instructor, rank, row_number()over(partition by id_number order by date_of_training desc ) rn
    from tbl_training)
    where rn =1;

  • Updating multiple records based on process date

    Hello,
    I need to change the value of multiple records in one table if a condition is met for each record in another table when the application is run.
    I have an Employee table containing employee names that also has a status field where the values are either "Active" or "Disabled".
    There is a form in the application with an employee name select list using a dynamic LOV based on the Employee table. The LOV is restricted to "Active" employees. The form inserts employee-related transactions with the current date into the Transaction table.
    I want to automatically update the status of all employees in the Employee table from "Active" to "Disabled" where there have been no transactions in the Transaction table for that employee for more than 2 months. This will allow me to exclude them from the dynamic LOV based on the Employee table.
    Any suggestions are greatly appreciated.
    Thank you,
    Matt

    Hi Matt
    Something like this?
    UPDATE employees
    SET status = 'Disabled'
    WHERE status = 'Active'
    AND NOT EXISTS(SELECT 'X'
                                      FROM transactions
                                      WHERE emp_id = trn_emp_id
                                     AND tran_date >= SYSDATE - INTERVAL '60' DAY);Let me know if I've misunderstood...
    Cheers
    Ben

  • Selecting unique records- Removing consecutive same data

    HI,
    am having a table where in some x,y,msg_date_info fields are there...here the data is in huge number...i need to fetch the data from this table subject to the following query conditions.
    SELECT  X longit,Y latit,MSG_DATE_INFO,row_number() over (order by MSG_DATE_INFO asc) SlNo FROM
    (SELECT distinct x,y,MSG_DATE_INFO,row_number() over (order by MSG_DATE_INFO desc) r
      FROM TRACKING_REPORT WHERE MSISDN='123456789') WHERE R between 1 and 20this works fine...
    here one more thing i want to add up...this query results in 20 rows as expected and i want to filter the records if consecutive x and y values of these rows are same and give only unique values of x and y(condition that same x and y can be there somewhere in the order of data).
    this example will show what is my requirement in detail....and this is the output of the above query
    >
    80.20550609     13.09469998     08-Mar-10 19:23:23     1
    80.20550609     13.09469998     08-Mar-10 19:28:37     2
    80.20087123     13.09437811     08-Mar-10 19:33:25     3
    80.20550609     13.09469998     08-Mar-10 19:38:24     4
    80.20550609     13.09469998     08-Mar-10 19:43:25     5
    80.20550609     13.09469998     08-Mar-10 19:48:25     6
    80.20087123     13.09437811     08-Mar-10 19:53:25     7
    80.20087123     13.09437811     08-Mar-10 19:58:24     8
    80.20550609     13.09469998     08-Mar-10 20:03:25     9
    80.20087123     13.09437811     08-Mar-10 20:08:24     10
    80.20550609     13.09469998     08-Mar-10 20:13:24     11
    80.20087123     13.09437811     08-Mar-10 20:18:37     12
    80.20550609     13.09469998     08-Mar-10 20:23:32     13
    80.20550609     13.09469998     08-Mar-10 20:28:25     14
    80.20550609     13.09469998     08-Mar-10 20:33:23     15
    80.20550609     13.09469998     08-Mar-10 20:38:24     16
    80.20550609     13.09469998     08-Mar-10 20:43:24     17
    80.20550609     13.09469998     08-Mar-10 20:48:24     18
    80.20550609     13.09469998     08-Mar-10 20:53:22     19
    80.20550609     13.09469998     08-Mar-10 20:58:24     20
    >
    from this output i need to filter out CONSECUTIVE unique x and y values. and the output has to be like
    >
    80.20550609     13.09469998     08-03-10 19:23     1
    80.20087123     13.09437811     08-03-10 19:33     3
    80.20550609     13.09469998     08-03-10 19:48     6
    80.20087123     13.09437811     08-03-10 19:53     7
    80.20550609     13.09469998     08-03-10 20:03     9
    80.20087123     13.09437811     08-03-10 20:08     10
    80.20550609     13.09469998     08-03-10 20:13     11
    80.20087123     13.09437811     08-03-10 20:18     12
    80.20550609     13.09469998     08-03-10 20:58     20
    >
    how to go about this requirement?
    Edited by: Aemunathan on Mar 9, 2010 5:45 PM

    The following gives the same results on your test data but maybe it's more accurate because searches both for changes in x and in y:
    SQL> with mytab as (
      2  select 80.20550609 x, 13.09469998 y, '08-Mar-10 19:23:23' mydate, 1 rn from dual union
      3  select 80.20550609,13.09469998, '08-Mar-10 19:28:37', 2 from dual union
      4  select 80.20087123,13.09437811, '08-Mar-10 19:33:25', 3 from dual union
      5  select 80.20550609,13.09469998, '08-Mar-10 19:38:24', 4 from dual union
      6  select 80.20550609,13.09469998, '08-Mar-10 19:43:25', 5 from dual union
      7  select 80.20550609, 13.09469998, '08-Mar-10 19:48:25', 6 from dual union
      8  select 80.20087123, 13.09437811, '08-Mar-10 19:53:25', 7 from dual union
      9  select 80.20087123, 13.09437811, '08-Mar-10 19:58:24', 8 from dual union
    10  select 80.20550609, 13.09469998, '08-Mar-10 20:03:25', 9 from dual union
    11  select 80.20087123, 13.09437811, '08-Mar-10 20:08:24', 10 from dual union
    12  select 80.20550609,13.09469998, '08-Mar-10 20:13:24', 11 from dual union
    13  select 80.20087123, 13.09437811, '08-Mar-10 20:18:37', 12 from dual union
    14  select 80.20550609, 13.09469998, '08-Mar-10 20:23:32', 13 from dual union
    15  select 80.20550609, 13.09469998, '08-Mar-10 20:28:25', 14 from dual union
    16  select 80.20550609, 13.09469998, '08-Mar-10 20:33:23', 15 from dual union
    17  select 80.20550609, 13.09469998, '08-Mar-10 20:38:24', 16 from dual union
    18  select 80.20550609, 13.09469998, '08-Mar-10 20:43:24', 17 from dual union
    19  select 80.20550609, 13.09469998, '08-Mar-10 20:48:24', 18 from dual union
    20  select 80.20550609, 13.09469998, '08-Mar-10 20:53:22', 19 from dual union
    21  select 80.20550609, 13.09469998, '08-Mar-10 20:58:24', 20 from dual
    22  )
    23  select x, y, mydate, rn from (
    24  select x, y, mydate, rn, nvl(lead(x) over (order by rn),0) next_x
    25         , nvl(lead(y) over (order by rn),0) next_y
    26  from mytab
    27  ) where next_x != x or next_y != y;
                       X                    Y MYDATE                               RN
             80.20550609          13.09469998 08-Mar-10 19:28:37                    2
             80.20087123          13.09437811 08-Mar-10 19:33:25                    3
             80.20550609          13.09469998 08-Mar-10 19:48:25                    6
             80.20087123          13.09437811 08-Mar-10 19:58:24                    8
             80.20550609          13.09469998 08-Mar-10 20:03:25                    9
             80.20087123          13.09437811 08-Mar-10 20:08:24                   10
             80.20550609          13.09469998 08-Mar-10 20:13:24                   11
             80.20087123          13.09437811 08-Mar-10 20:18:37                   12
             80.20550609          13.09469998 08-Mar-10 20:58:24                   20
    9 rows selected.Max
    http://oracleitalia.wordpress.com

  • Sql query - Selecting last recorded values for each date in specified period

    Hello,
    Can someone please help me with my problem.
    I'm trying to get last recorded balance for each day for specific box (1 or 2) in specified period of days from ms access database using ADOTool.
    I'm trying to get that information with SQL query but so far unsuccessfully...  
    My table looks like this:
    Table name: TestTable
    Date Time Location Box Balance
    20.10.2014. 06:00:00 1 1 345
    20.10.2014. 12:00:00 1 1 7356
    20.10.2014. 18:45:00 1 1 5678
    20.10.2014. 23:54:00 1 1 9845
    20.10.2014. 06:00:02 1 2 35
    20.10.2014. 12:00:04 1 2 756
    20.10.2014. 18:45:06 1 2 578
    20.10.2014. 23:54:10 1 2 845
    21.10.2014. 06:00:00 1 1 34
    21.10.2014. 12:05:03 1 1 5789
    21.10.2014. 15:00:34 1 1 1237
    21.10.2014. 06:00:00 1 2 374
    21.10.2014. 12:05:03 1 2 54789
    21.10.2014. 15:00:34 1 2 13237
    22.10.2014. 06:00:00 1 1 8562
    22.10.2014. 10:00:00 1 1 1234
    22.10.2014. 17:03:45 1 1 3415
    22.10.2014. 22:00:00 1 1 6742
    22.10.2014. 06:00:05 1 2 562
    22.10.2014. 10:00:16 1 2 123
    22.10.2014. 17:03:50 1 2 415
    22.10.2014. 22:00:10 1 2 642
    23.10.2014. 06:00:00 1 1 9876
    23.10.2014. 09:13:00 1 1 223
    23.10.2014. 13:50:17 1 1 7768
    23.10.2014. 19:47:40 1 1 3456
    23.10.2014. 21:30:00 1 1 789
    23.10.2014. 23:57:12 1 1 25
    23.10.2014. 06:00:07 1 2 976
    23.10.2014. 09:13:45 1 2 223
    23.10.2014. 13:50:40 1 2 78
    23.10.2014. 19:47:55 1 2 346
    23.10.2014. 21:30:03 1 2 89
    23.10.2014. 23:57:18 1 2 25
    24.10.2014. 06:00:55 1 1 346
    24.10.2014. 12:30:22 1 1 8329
    24.10.2014. 23:50:19 1 1 2225
    24.10.2014. 06:01:00 1 2 3546
    24.10.2014. 12:30:26 1 2 89
    24.10.2014. 23:51:10 1 2 25
    Let's say the period is 21.10.2014. - 23.10.2014. and I want to get last recorded balance for box 1. for each day. The result should look like this:
    Date Time Location Box Balance
    21.10.2014. 15:00:34 1 1 1237
    22.10.2014. 22:00:00 1 1 6742
    23.10.2014. 23:57:12 1 1 25
    So far I've managed to write a query that gives me balance for ONLY ONE date (date with highest time in whole table), but I need balance for EVERY date in specific period.
    My incorrect code (didn't manage to implement "BETWEEN" for dates...):
    SELECT TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
    FROM TestTable
    WHERE Time=(SELECT MAX(Time)
    FROM TestTable
    WHERE Location=1 AND Box=1 );
    Tnx!
    Solved!
    Go to Solution.

    For loop
    following query keep day (here 24 in below query) Variable from ( 1 to 28-29/30/31 as per month)
    SELECT TOP 1 TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
    FROM Test Table.
    WHERE  Time=(SELECT MAX(Time) FROM TestTable WHERE Location=1 AND Box=1 )
    AND DATE = "2014-10-24";
    PBP (CLAD)
    Labview 6.1 - 2014
    KUDOS ARE WELCOMED.
    If your problem get solved then mark as solution.

  • Dynamic selection of records based on checkbox checked

    Hello,
    I want to select a list of records from a multirecord block by
    using the checkbox checked values as the criterion and use the
    records selected in the where clause for querying in another
    forms. The data from the multirecord block is from a query
    result and hence is dynamic.
    I went about doing this:
    I created a multirecord block. In the multirecord block, I
    created a checkbox which was a non-database item.
    In the when_button_pressed trigger I wrote the following code:
    declare
         temp varchar2(1000);
         start_rec number;
         stop_rec number;
         item_id item;
         block_id block;
         item_value varchar2(1000);
         pl_id paramlist;
         item_name varchar2(10);
         patient_list varchar2(1000);
    begin
    go_block('patient_list');
    block_id:=find_block('patient_list');
    start_rec:=1;
    stop_rec:=get_block_property(block_id,query_hits);
    for i in start_rec..stop_rec loop
    if :selection='Y' then --selection is the checkbox           
         if item_value is null then
    /*item_value holds the value of the data shown in the forms &
    for which the checkbox is checked*/
    item_value:=name_in(':patient_list.patient_id');
    /*patient_id is the item name as well as field name in the
    table*/
         else
    item_value:=item_value||','||name_in(':patient_list.patient_id');
         end if;
    end if;
    end loop;
    patient_list:='('||item_value||')';
    pl_id:=create_parameter_list('list_of_patients');
    add_parameter(pl_id,'querypatients',text_parameter,patient_list);
    message(patientlist);
    run_product
    (forms,'patient_history',synchronous,runtime,filesystem,pl_id,nul
    l);
    end;
    When I run this form, patient_list comes as
    (111,111,111,111,111,111,111) where
    111 is the value of the patient_id.
    The only value that gets into the patient_list is the patient_id
    for the last checkbox I have
    checked in the forms and the same patient_id appears so many
    times.
    Can anyone tell me where I am doing the mistake? Why is the same
    value appearing so many times and only the last record selected
    appears in the patient_list.
    Thank you for your suggestions.

    Thank You.
    I added go_record(start_rec) and next_record and everything
    worked fine.
    Here I have the working code:
    declare
         temp varchar2(1000);
         start_rec number;
         stop_rec number;
         item_id item;
         block_id block;
         item_value varchar2(1000);
         pl_id paramlist;
         item_name varchar2(10);
         patient_list varchar2(1000);
    begin
         go_block('patient_list');
         block_id:=find_block('patient_list');
         start_rec:=1;
         stop_rec:=get_block_property(block_id,query_hits);
    go_record(start_rec);-- I added it
         for i in start_rec..stop_rec loop
         if :selection='Y' then --selection is the checkbox in  
    the patient_list block.
         if item_value is null then
    -- item_value holds the value of the data shown in the forms and
    for which the checkbox is checked
         item_value:=name_in(':patient_list.patient_id');
    -- patient_id is the item name as well as field name in the table
         else
         item_value:=item_value||','||name_in
    (':patient_list.patient_id');
         end if;
         end if;
    next_record;-- I added it
         end loop;
    patient_list:='('||item_value||')';
    pl_id:=create_parameter_list('list_of_patients');
    add_parameter(pl_id,'querypatients',text_parameter,patient_list);
    message(patientlist);
    run_product
    (forms,'patient_history',synchronous,runtime,filesystem,pl_id,nul
    l);
    end;

  • Choosing unique record based on latest date

    I have a column, say Name, in which a person's name appears with multiple transactions. Each transaction has an unique date. I want to return just the latest transaction by date for each person.
    If I write my select as:
    select Name, Trans_Dt from <Table>;
    I of course get a list of all transactions listing person and date.
    I've tried this:
    select Name, Trans_Dt from <Table>
    group by Trans_Dt having greatest(Trans_Dt).
    This doesn't work. Any suggestions?

    select name, trans_dt
    from
       select
          Name,
          Trans_Dt,
          max(Trans_Dt) over(partition by name) as max_trans_date
       from <Table>
    where Trans_Dt= max_Trans_trans_date;Would be one way.

  • Select distinct record based on column

    Hello All,
    I have a table that has more than one row as Detail for a single invoice number(screenshot below). When I create report based on this table, I get multiple rows for single invoice. I mean Invoice 000027 shows up with 5 different rows on the SSRS report.
    Is there a way I could display a single row for a single invoice? Any thoughts on this will be greatly appreciated. Thanks.
    Regards,
    Amol
    eport )

    Thank you all for your suggestions. The issue is how can I get single distinct columns after joining 2 tables (InvoiceHeader & InvoiceDetail). I am using following query in my dataset.
    SELECT DISTINCT I.recid, I.InvNumber, D.Detail, I.CompanyName, I.Addr1, I.SalesRep, I.JobNumber, I.Status, I.InvDate, I.TotalInvAmount
    FROM            InvoiceHeader AS I INNER JOIN
                             InvoiceDetails AS D ON I.InvNumber = D.InvoiceNumber
    WHERE        (I.InvNumber = @InvoiceNumber) AND (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) OR
                             (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (I.JobNumber = @JobNo) OR
                             (I.InvNumber = @InvoiceNumber) AND (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) 
                             AND (@JobNo = '') OR
                             (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (I.JobNumber = @JobNo) AND 
                             (@JobNo = '') OR
                             (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (@JobNo = '') AND 
                             (@InvoiceNumber = '')
    ORDER BY I.InvNumber DESC
    Thanks again.
    Amol

  • Select distinct rows based on latest date

    Hi
    I need to produce data from two tables and return results where only data for the latest OriginationDate is returned  for each unique client. I have been trying all sorts of combinations but with no success. Any help would be appreciated
    e.g
    select
    c.client_no
    ,c.forename
    ,c.surname
    ,c.tel_no1
    ,c.tel_no2
    ,c.tel_no3
    ,o.ordernumber
    ,o.propertyidentifier
    ,o.contractorlongname
    ,o.OrderStatus
    ,o.CancelReasonDesc
    ,o.OriginationDate
    ,o.Completed
    ,DATEDIFF(d,o.OriginationDate,GETDATE())
    as Total
    FROM
    hgmclent AS c
    LEFT
    OUTER
    JOIN QLHPM_Order_Summary
    AS o
    ON
    c.client_no
    = o.ClientNumber
    WHERE
    o.Ordernumber
    IS
    NOT
    NULL
    GROUP
    BY c.client_no
    ,c.forename
    ,c.surname
    ,c.tel_no1
    ,c.tel_no2
    ,c.tel_no3
    ,o.ordernumber
    ,o.propertyidentifier
    ,o.contractorlongname
    ,o.OrderStatus
    ,o.CancelReasonDesc
    ,o.OriginationDate
    ,o.Completed
    Currently this produces the following data from which I have hidden sensitive information. What I need to show for client_no 1 is repair order 6353 which was reported on 2015-01-06 00:00:00.000 being the most recent of 12 orders for this client,
    Client No2 only has one order so this will be shown
    Client No3 should only show order number 6842 reported on 2015-01-19 00:00:00.000
    and so on.
    Can anyone help with this
    Thanks
    John

    I think he needs to return the data for the latest OriginationDate, so ORDER BY o.Completed DESC should be changed to
    ORDER BY o.OriginationDate DESC
    Row_number() Over(Partition
    by c.client_no Order
    by  o.OriginationDate
    DESC ) rn
    A Fan of SSIS, SSRS and SSAS

  • Select the record based count condition

    Hi Experts
    I have a table with columns  StateDate,State,Name & Type . For the same date there could be 2 or more rows for the same name .
    I need to retrieve the data from the table only for the name containing single row in the table and state = 'On'
    Please find the Create & Insert Scripts below . Am assuming it needs to be done with a window function and am not yet comfortable with window function .
    CREATE TABLE ItemState
    (StateDate Date,
    State Varchar(3),
    Name Varchar(3),
    Type int)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','On','XYZ',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','Off','XYZ',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','On','ABC',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/12/2014','Off','CBR',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/12/2014','On','CBR',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/12/2014','On','XYZ',1)
    Expected Result
    StateDate
    State
    Name
    Type
    3/11/2014
    ON
    ABC
    1
    3/12/2014
    ON
    XYZ
    1
    Kindly help
    Thanks
    Priya

    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','On','XYZ',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','Off','XYZ',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','On','ABC',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/12/2014','Off','CBR',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/12/2014','On','CBR',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/12/2014','On','XYZ',1)
    again adding this 3 rows 
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','On','XYZ',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','Off','XYZ',1)
    INSERT INTO Itemstate (Statedate,State,Name,Type)
    Values ('3/11/2014','On','ABC',1)
    SELECT *
    FROM   itemstate order by statedate, name,state
    2014-03-11 On
    ABC 1
    2014-03-11 On
    ABC 1
    2014-03-11 Off
    XYZ 1
    2014-03-11 Off
    XYZ 1
    2014-03-11 On
    XYZ 1
    2014-03-11 On
    XYZ 1
    2014-03-12 Off
    CBR 1
    2014-03-12 On
    CBR 1
    2014-03-12 On
    XYZ 1
    so only xyz on 2014-03-12 will qualify
    WITH test
         AS (SELECT *,
                    row_number()
                      OVER (
                        partition BY statedate, name
                        ORDER BY state ASC) rnasc, 
    count(state)
                      OVER (
                        partition BY statedate, name
                        ORDER BY state desc) rncount
             FROM   itemstate)
    SELECT *
    FROM   test t1  where rnasc = 1 
    and state = 'on' and rncount = 1
    Amish shah
    http://bloq.sqltechie.com

  • Sort all the Records in Data manager based on Update Date

    How to sort the reocrds in Data Manager based on Date or something ?
    And also I have three records for a same customer in ( for three different company codes ) and when I search for this customer with the Customer number then it is showing three records , but when I search with Update Date then no records are fetched ...what is the reason ?

    If you make a field as type "Time Stamp" in your data model using the MDM Console, make sure that the option Sort Index is set to Normal.  If this is the case, whenever a record is updated in the repository, the date will be updated.  If the sort index is normal, then MDM will allow you to sort the records based on the date and time by which they were updated.  You can do this by finding your time stamp field in the MDM data manager and clicking on it.  If there is an up and down arrow next to the name of your field, it means it can be sorted.  Also, to answer your other question, you can definitely search based on date.  Use the Free-Form Search on the left hand side of the data manager at the bottom of the screen.  Simply select a date, and it will show you all the records updated on that date.

  • SQL Query to retrieve the All records based on the Max Dates.

    Hello all,
    I am trying to retrieve the newest record based on the date field (  nextDate  ).
    Currently there are only 4 records in the MC_Maintenance table and two in the Machine table.
    Machine table
    MC_id             EquipID          
    1                      0227
    MC_id             EquipID
    2                     0228
    MC_Maintenance table
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010     
    2                      2                      07/01/2010
    3                      1                      06/11/2010
    4                      1                      07/11/2010
    What I  am trying to accomplish is,
    list the two machines from the Machine table with the MAX(Next_maint) controlling the MC_Maintenance output list
    These are the records that I would like to Display.
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010
    4                      1                      07/11/2010                 
    Below is the SQL Query
    SELECT
           MC.MC_ID as ID,
            MC.complete_Date as completed,
            MC.next_maint as nextDate,
            MC.maint_notes as Notes,
            MC.facility as Facility,
            M.EquipId,
            M.name as name,
            M.SerialNumber as SN,
            M.dept as dept,
            M.Freq as freq
            From  MC_Maintenance MC, Machine M
            where  MC.MC_ID =  M.MC_ID
    '           USING MAX(nextDate )
    Any ideas would help.
    TJ

    I would have thought that was a simple group by problem?
    SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
    FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
    GROUP BY M.EquipID, MC.MC_ID

  • Select records based on criteria and update those records once read

    hi,
    I am very new to bpel and DB adapters.
    I have a requirement where in I need to query two tables to fetch some records and update these selected records with a new value for field to indicate that bpel has processed these records.
    Once I select these I needs the output to be mapped to the output variable.
    I am able to select the records based on criteria , but how will i lock these records so that these records do not get processed again. This should be a very simple usecase just that I am not aware.
    Thanks,
    Robin

    Once you have finished reading the records fire an update query , update some field in the table so that it does not get picked up next time.
    if you are using polling for picking up the records, then use logical delete scenario, refer....http://docs.oracle.com/cd/E15523_01/integration.1111/e10231/adptr_db.htm#BABEEBIH

Maybe you are looking for

  • Not able to post outbound delivery  due to error VL150

    Hi Guru, I am trying to post a return to the vendor by a returns PO. i am using VL10B to create a outbound delivery. But unfortunately the outbound delivery is created but delivery quantity is not copied from the PO.  After creating a outbound delive

  • Process order release problem

    Hai All, I have created a process order and when i am releasing the same, following error is coming and system is not allowing to release the process order. Resource T-DTM100 in operation 0200 does not meet resource selection conditions How to solve

  • "Capacity must be greater than 0" error message

    Hi experts, I'm having some issues when trying to full optimize my application (on BPC 5.1). I get the following error: Capacity must be greater than zero. Parameter name: Capacity Save application and process from Analysis Services work without a co

  • IPhone und iMatch: exceeded capacity by 17GB

    Hello everybody, after I've turned on iTunes Match for my iPhone it did not delete the whole music that was on it, it just added the whole catalogue of what is available in the cloud - everything as expected. iTunes however constantly claims on its i

  • What is the best way to setup network so its FASTEST?

    Hello, I have an old airport plugged into my cable provider box, and use one macbook pro core duo on it, and one new imac on it. But lately i transfer from the internet a lot of big files, and i wan't the fastest network connection for my imac. Shoul