Share via

Extract latest date and time

jn93 671 Reputation points
2022-10-18T03:47:02.823+00:00

Hi lets say I have the data like below. Based on the desired output, how can I extract latest date and time based on the primary key of UKEY and PACODE? I'm using SSIS, please let me know of the solution. If there is solution using SQL code, also could be good since I'm going to transfer data from sql to another sql db, below in txt file is just for example. Thanks and Regards.

![251357-image.png]1

SQL Server Integration Services
0 comments No comments

Answer accepted by question author
  1. ZoeHui-MSFT 41,551 Reputation points
    2022-10-18T06:09:01.923+00:00

    Hi @jn93 ,

    You may try with TSQL code to do that easily. It will be a little hard to do that in SSIS.

     select ukey,pacpde,date,time from (  
         select *,row_number() over(partition by ukey,pacpde order by date desc,time desc) as rn  
         from  
             test1018  
     ) t  
     where t.rn = 1  
    

    251319-image.png

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.