How to get minimum of 3 identical records with different dates

Hi All,
Below is my query which gives me the data i want but it gives me a same claim number 3 times because those 3 records have HVAC in them but the comments date is different, So i would like to have one row returned with the min(commentdate).
SELECT C.hsclaimnumber,
COMMENTS.hsobjectid ,
COMMENTS.hsnote as Comment,
C.hsdatecreated,s.state_id,
l.hslosstype,
Comments.hsDateCreated AS CommentDate
FROM hs_comments AS COMMENTS
INNER JOIN
hs_claim AS C ON COMMENTS.hsobjectid = C.hsclaimid
inner join
qx_states s on s.pkey = c.hslosslocationstate
inner join
[dbo].[hs_loss_type] l on C.hslosstypeid = l.hslosstypeid
WHERE (COMMENTS.hsnote LIKE '%hvac%') and
year(c.hsdatecreated) in (2014) AND (l.hslosstype = 'All other physical damage' or l.hslosstype ='Lightning (no fire)' or l.hslosstype ='Water')
group by C.hsclaimnumber,
COMMENTS.hsobjectid ,
COMMENTS.hsnote ,
C.hsdatecreated,s.state_id,
l.hslosstype,
Comments.hsDateCreated
order by C.hsclaimnumber
Can someone please help me with this?
Thanks.

Select * from (SELECT C.hsclaimnumber,
COMMENTS.hsobjectid ,
COMMENTS.hsnote as Comment,
C.hsdatecreated,s.state_id,
l.hslosstype,
Comments.hsDateCreated AS CommentDate
,row_number() Over(partition by C.hsclaimnumber Order by Comments.hsDateCreated) rn
FROM hs_comments AS COMMENTS
INNER JOIN
hs_claim AS C ON COMMENTS.hsobjectid = C.hsclaimid
inner join
qx_states s on s.pkey = c.hslosslocationstate
inner join
[dbo].[hs_loss_type] l on C.hslosstypeid = l.hslosstypeid
WHERE (COMMENTS.hsnote LIKE '%hvac%') and
year(c.hsdatecreated) in (2014) AND (l.hslosstype = 'All other physical damage' or l.hslosstype ='Lightning (no fire)' or l.hslosstype ='Water')
group by C.hsclaimnumber,
COMMENTS.hsobjectid ,
COMMENTS.hsnote ,
C.hsdatecreated,s.state_id,
l.hslosstype,
Comments.hsDateCreated
) T
WHERE rn=1
order by C.hsclaimnumber

Similar Messages

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • Adobe: How to print the documents more than once with different data.

    Hi Experts,
    I have a requirement to print the document of minimum 5 employee's at a time.
    First we are displaying the list of employee's and then the user is provided an option to select the employee's and print their details.
    A form has been created. We are able to print the document for a single employee. But now the requirement is to select multiple employee's and print their details at one time.
    I am able to get the contents all the employee's in an internal table. But i am not getting to combine the contents together and print the document.
    So could some one help me how to get the contents of all the selected employee's and print the document's.
    Thanks.

    I don't understand whether you want to print several different documents in a row each with  an employee or one pdf document with several employees in it.
    If you want to print one document with multiple employees inside, then you have to recode your PDF to be able to handle a table containing each employee data.
    If you want to print multiple pdf documents each containing one employee info, then this is done in abap. [see BC480]
    i.e.
    DATA:
    gt_customers TYPE TABLE OF scustom,
    gs_customer LIKE LINE OF gt_customers,
    gt_bookings TYPE ty_bookings, "table of sbook
    gt_sums TYPE flprice_t,
    gv_image_url TYPE string,
    gv_fm_name TYPE rs38l_fnam,
    * parameters for calling the generated function module
    gs_docparams TYPE sfpdocparams,
    gs_outputparams TYPE sfpoutputparams,
    Event START-OF-SELECTION:
    * Please note that the error handling implemented here is very
    * rudimentary!
    *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    * Get name of the generated function module
    TRY.
    CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
    EXPORTING
    i_name = pa_form
    IMPORTING
    e_funcname = gv_fm_name.
    CATCH cx_root.
    MESSAGE e004 WITH pa_form.
    * No active form &1 available
    ENDTRY.
    *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    * Optional: Set output parameters
    gs_outputparams-nodialog = space.
    gs_outputparams-preview = 'X'.
    gs_outputparams-dest = pa_prnt.
    *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    * Open print job
    CALL FUNCTION 'FP_JOB_OPEN'
    CHANGING
    ie_outputparams = gs_outputparams
    EXCEPTIONS
    OTHERS = 1.
    IF sy-subrc <> 0.
    MESSAGE e020.
    * Form processing could not be started
    ENDIF.
    LOOP AT gt_customers INTO gs_customer.
    * Set form language and country (->form locale)
    gs_docparams-langu = pa_lang.
    gs_docparams-country = pa_cntry.
    PERFORM find_bookings_for_customer.
    *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    * Now call the generated function module
    CALL FUNCTION gv_fm_name
    EXPORTING
    /1bcdwb/docparams = gs_docparams
    is_customer = gs_customer
    it_bookings = gt_bookings
    it_sums = gt_sums
    iv_image_url = gv_image_url
    iv_sending_country = pa_cntry
    EXCEPTIONS
    OTHERS = 1.
    IF sy-subrc <> 0.
    MESSAGE e021.
    ENDIF.
    ENDLOOP.
    *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    * Close spool job
    CALL FUNCTION 'FP_JOB_CLOSE'.
    In the above pay attention to the loop.
    Cheers,

  • How to get the pricing hierarchy based on the delivery date for sales order

    Hi,
    How to get the pricing hierarchy based on the delivery date for sales order other than system date.
    My requirement is to get the Pricing hierarchy based on the delivery date other than system date.
    Waiting for kind response.
    Best Regards,
    BDP

    HI Sai,
    please refer teh document already how to write FM based extration on generic extractors.
    and here  the logic to find the latest records values:-
    -> get the data in an internal table
    ->Sort the internal table data based from date descending
    -> Using READ statement , we can read the first record of the table which is nothign but your latest record.
    Regards.
    Sakthi

  • How to get rid of the blue underline with green arrows on words and then a pop-up ad appears.

    How to get rid of the blue underline with green arrows on words and then a pop-up ad appears.

    Click here and follow the instructions, or if they don't cover the type of adware on the computer, these ones. If you're willing to use a tool to remove it(you don't need to, but may find it easier), you can instead run Adware Medic; this link is a direct download.
    (119795)

  • How to get all images in indesign CS5 with javascript?

    Hi,everybody,
    How to get all images in indesign CS5 with javascript?I want to delete them.
    Anyone can give me some example codes?
    Thanks,
    Bridge

    Hey!
    This will remove all images from your InDesign document:
    var myLinks = app.activeDocument.links.everyItem().parent;
    for(var i = 0; i < myLinks.length; i++)
        myLinks[i].remove();
    Hope that helps.
    tomaxxi
    http://indisnip.wordpress.com/
    http://inditip.wordpress.com/

  • How to get the stock of STO Report with suppling Plant/receiving Plant/open

    How to get the stock of STO Report with suppling Plant/receiving Plant/open/close qty.

    MB5T gives you Details of STO which have stok in transit.
    ME2W gives you supplying plant wise STO details.  Also in ME2W , in the ALV report output, if you select  the "delivery Schedule line" icon , you will get details such as , STO qty, Issued qty , undelivered qty etc.

  • How to get the iPhone 5c to pair with my mac book pro and my ue speaker

    How to get the iphone 5c to pair with my mac book pro and my ue speaker

    TerryReynar wrote:
    How to get the iphone 5c to pair with my mac book pro
    You don't. It only sync using iTunes.
    It doesn't "pair".
    and my ue speaker
    What is "ue speaker"?
    Ultimate Ears wirless bluetooth speaker?
    Set speaker to Pairing mode.
    On the iPhone, Settings > BlueTooth.
    Select the speaker.

  • How to get the 4 digit number associated with a SAP icon ( ICON_MAIL )

    Hi Friends,
                   Could anyone please tell me how to get the 4 digit number associated with a SAP icon ( ICON_MAIL ).
                   eg: - For ICON_GREEN_LIGHT the four digit id code is '@08@' (which you can get from ICON table )and the associated 4 digit number is'1003'.
                  Similarly I want to get the 4 digit number for ICON_MAIL(e-mail icon)
    <b><REMOVED BY MODERATOR></b>
    Ashiq
    Message was edited by:
            Alvaro Tejada Galindo

    You can use this report...It's not mine...
    REPORT zdummy_atg_2.
    TABLES: ICON.
    INCLUDE <ICON>.
    FIELD-SYMBOLS: <F>.
    SELECT * FROM ICON.
       ASSIGN (ICON-NAME) TO <F>.
       WRITE:   /(5) <F>, 20 '@',21 ICON-ID+1(2),23 '@',ICON-OLENG,
                ICON-BUTTON,ICON-STATUS,ICON-MESSAGE,ICON-FUNCTION,
                ICON-NAME.
    ENDSELECT.
    Greetings,
    Blag.

  • How to get an N wireless USB adapter to transfer data faster that 54 Mbps

    How to get an N wireless USB adapter to transfer data faster that 54 Mbps? I am running FIOS 10/2 and connected to a ActionTec  M1424WR router. Any help will be appreciated.

    I have to ask the question, why are you in need of 802.11N speeds?  Are you transferring lots of files between other PC's on your network or are you simply connecting to the Internet.  
    Remember if your Internet speed is 10/2 which means 10 meg down and 2 meg up having 300 meg capability WLAN connection will not be noticeable.   Your bottleneck is your Internet connection of 10/2.   

  • How to get slideshow to Pause and restart with auto play enabled? all slideshow do not restart!

    How to get slideshow to Pause and restart with auto play enabled? Happening in all slideshow do not restart once one photo is selected

    I agree cwclark, I was going to ask the exact same thing, and yes, the only way to 'restart' the auto play is to reload the page which is frustrating to say the least. Every other site I've seen with this kind of 'auto-play' slide show still auto-plays even after clicking the 'next' or 'previous' buttons. Adobe, you need to get a fix for this ASAP

  • How to complain to Apple about this company and how to get a formally answer for problem with Apple agent in Kuwait??

    How to complain to Apple about this company and how to get a formally answer for problem with Apple agent in Kuwait??

    You did not buy your iphone from an Apple store.  No Apple employee sold you anything.
    Your complaint is not with Apple.  You bought from an unauthorized seller.  Your complain is with that seller.
    As you have been told more than once, Apple has nothing to do with this.

  • How to get imac 27 inch to work with asus triple mionitors to work through matro triple head 2 go

    how to get imac 27 inch to work with asus triple mionitors to work through matro triple head 2 go

    I think I got a little ahead of myself explaining my problem, so let me clarify...
    Only the one iMac is having the network file deletion problem, but it is included in the network user logon problem.  So 4 out of 5 of the iMacs have had or are having logon problems with network users accounts using mobile accounts on the systems.  2 of the 4 I have wiped and started over on and the other 2 have different network accounts being used by the primary system users.  The 5th iMac has not caused any problems except I forgot to mention that the USB on it seems flaky.
    So we are apparently full of problems. 

  • How can I make a report of all records with the date in the last two weeks?

    Hi!
    I have records with a date field, I want to create a report that only includes records with a date which is within the last two weeks of the system date, is this possible? Surely this is a basic database function, I would have thought, but I can find no help about it and there's very little in Mac Help about doing anything other than simple stuff with reports.
    I'm not a genius with databases, so help with any required formula or what have you would be great!

    Hi Jonathan,
    Here's a formula you can use with the Match function. 'Date' is the name of the date field, which must be a "Date" type field.
    'Date'>NOW()-14
    Match will select (highlight) all records matching the query. You'll then need to use Organize > Hide Unselected to show only the matches.
    Unfortunately, I haven't found a way to make the NOW() function work in a Find request, and neither Match requests nor Hide Unselected can be included in a recorded search, either of which would reduce repeating the report to a one-button operation.
    Regards,
    Barry

  • How to go about multiple inclination with different data selection in Delta

    We have to copy large amount of data ( more than 42lak of recodes) selectivly from on ODS to other ODS. in delata load ( BW 3.5 enverioment)
    I thought of loading data in slices through delta loading with selection condition.
    step 1> Do The initialization with selection condition as for calyear =2001 ( Init without data transfer )
    step 2> Take the delta load .. it will take all delta record with same selection
    step 3> Now I want to do Initialization with selection condition as for calyear =2002
    step 4> take the delta now it will take delta for year 2001 and 2002 both Right ?
    Here what problem I am facing.. while doing 2nd time initialization it prompt me to delete the last  initialization request form scheduler menu.
    if i delete the last request .. will it take the delta  for previous initialization selection  and new initialization selection. ?
    Please advice how to go about multiple inclination with different data selection in delta loading.
    Looking forward your reply.

    Hi,
    step 1> Do The initialization with selection condition as for calyear =2001 ( Init without data transfer )
    step 2> Take the delta load .. it will take all delta record with same selection
    step 3> Now I want to do Initialization with selection condition as for calyear =2002
    step 4> take the delta now it will take delta for year 2001 and 2002 both Right ?
    You are correct with this scenario normally. The message you mentioned normally comes up when you open a infopackage and don't change the selection first or in case you have overlapping selections with an already done init.
    regards
    Siggi

Maybe you are looking for

  • DVD Studio Pro: is it possible to burn unusual resolution video on DVD?

    Hello All, FCP 0.6, DVD Studio Pro 4.2.1 Compressor 3.0.5 I have a short that has a resolution 1920 x 650 px (it is a split screen video). I am trying to burn it to DVD by using DVD Studio Pro. I tried to export the film from FCP by using Compressor.

  • Issue with REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hello All, I am trying to use REUSE_ALV_HIERSEQ_LIST_DISPLAY and am passing header and item level data in tables to the FM. It is displaying  the header fine, but when we click on the + sign the item level is not displaying any data. It seems the FM

  • Database error Ora-00604

    hi all i facing Ora-00604. before this error i am got ORA-12638: Credential retrieval failed Release 10.1.0.2.0 - Production on Tue Aug 15 17:11:27 2006 on Win2003Server then after i check Alert_orcl.log file and find Ora-00604 error last few lines o

  • Iphoto slideshows and powerpoint

    I made a powerpoint presentation using multiple iphoto slideshows and some qtvr movies. the presentation works great out of powerpoint but when I save it as a movie file the iphoto slideshows are blank. Is there a specific way to save the iphoto slid

  • Planned order number and Plnkn

    Dear All, I need the table link between planned order number and Number of the task list node(PLNKN). Thank you in advance Regards Sailendra.M Edited by: nivedita yadav on Jun 25, 2010 2:35 PM