sql - Get max date and max time -


i'd t.notes associated s.sr_service_recid has recent t.date_start , t.time_start - there can multiple time entries on single date against single ticket, need include time recent single result.

declare @sd datetime,         @ed datetime      set     @sd = dateadd(dd, -14, getdate()) set     @ed = getdate()  select s.sr_service_recid      , t.notes    sr_service s        left join time_entry t                on t.sr_service_recid = s.sr_service_recid   s.date_closed between @sd , @ed 

i have tried 2 sub-queries in clause, 1 t.date_start , 1 t.time_start select max results, limit results reason , there missing entries... not right way go?

    , t.date_start in         (             select  max(t.date_start)                time_entry t               t.sr_service_recid = s.sr_service_recid         )     , t.time_start in         (             select  max(t.time_start)                time_entry t               t.sr_service_recid = s.sr_service_recid         ) 

i think should close. mystery how combine whatever data types have separate dates , times single datetime value. that's left exercise op.

select *   (     select s.sr_service_recid, t.notes, t.date_start, t.time_start,       row_number() on ( partition s.sr_service_recid order <combined date/time> desc) [rn]       sr_service s left outer join         time_entry t on t.sr_service_recid = s.sr_service_recid       @sd <= s.date_closed , s.date_closed <= @ed     ) bob   rn = 1 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -