How to get the MAX & MIN using a CROSS APPLY in SQL Server? -


i have large query , part of this:

cross apply (select top 1                  employment.hiredate earliesthiredate,                  employment.terminationdate                                  intranetmig.dbo.employment employment                                 employment.employeeid = emp.employeeid                  , (employment.terminationdate null                       or employment.terminationdate > @inputperiodstart) order      employment.hiredate asc) eh 

this query "cross applying" on earliest hire date.

i use date elsewhere in query. thing is, need latest hire date. can't max() because that'll break cross apply.

how go selecting latest hire date while @ same time, cross applying earliest hire date?

easiest solution add cross apply:

 cross apply (select top 1                                       employment.hiredate latesthiredate,                                       employment.terminationdate                                  intranetmig.dbo.employment employment                                 employment.employeeid = emp.employeeid                                       , (                                            employment.terminationdate null                                            or employment.terminationdate >                                             @inputperiodstart                                           )                                order employment.hiredate desc) lhd 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -