title: SQL get max record that is less than or equal to a datetime paramter
body: <p>In SQL I'm trying to get most recent record for example (the max record which is less than or equal to a <code>datetime</code> parameter passed)</p>
  
  <p>For example in my table called <code>serviceentry</code> there is a column called <code>ServiceDateTime</code></p>
  
  <p>How do I apply Max in my select clause. So in the following if a part has a service entry, I want to get the max record based on my datetime parameter</p>
  
  <pre><code>select  
      Part.System as Subsystem, Part.ID as PartNumber, 
      Part.PartDescription, System.SystemFullName,
      COALESCE(ServiceEntryPart.PartRevisionNumber, Part.RevisionNumber) AS Revision
  from 
      Part
  left outer join 
      ServiceEntryPart on Part.ID = ServiceEntryPart.PartID
  left outer join 
      ServiceEntry on ServiceEntryPart.ServiceEntryID = ServiceEntry.ID
  left outer join 
      System on System.PlatformID = Part.platformid
  where
      part.id = 670220
      and ServiceEntry.ServiceDateTime &lt;= '1/1/2014'
  </code></pre>