title: SQL Query to update a colums from a table base on a datetime field
body: <p>I have 2 table called tblSetting and tblPaquets.
  I need to update 3 fields of tblPaquets from tblSetting base on a where clause that use a datetime field of tblPaquest and tblSetting.</p>
  
  <blockquote>
    <p><em>The sql below is to represent what I am trying to do and I know it make no sense right now.</em></p>
  </blockquote>
  
  <p>My Goal is to have One query to achieve this goal.</p>
  
  <p>I need to extract the data from tblSettings like this</p>
  
  <pre><code>SELECT TOP(1) [SupplierID],[MillID],[GradeFamilyID] FROM [tblSettings]
  WHERE [DateHeure] &lt;= [tblPaquets].[DateHeure]
  ORDER BY [DateHeure] DESC
  </code></pre>
  
  <p>And Update tblPaquets with this data</p>
  
  <pre><code>UPDATE [tblPaquets]
  SET( [SupplierID] = PREVIOUS_SELECT.[SupplierID]
       [MillID] = PREVIOUS_SELECT.[MillID]
       [GradeFamilly] = PREVIOUS_SELECT.[GradeFamilyID] )
  </code></pre>
  
  <p>Here the table design</p>
  
  <pre><code>CREATE TABLE [tblSettings](
      [ID] [int] NOT NULL,
      [SupplierID] [int] NOT NULL,
      [MillID] [int] NOT NULL,
      [GradeID] [int] NOT NULL,
      [TypeID] [int] NOT NULL,
      [GradeFamilyID] [int] NOT NULL,
      [DateHeure] [datetime] NOT NULL,
      [PeakWetEnable] [tinyint] NULL)
  
  CREATE TABLE [tblPaquets](
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [PaquetID] [int] NOT NULL,
      [DateHeure] [datetime] NULL,
      [BarreCode] [int] NULL,
      [Grade] [tinyint] NULL,
      [SupplierID] [int] NULL,
      [MillID] [int] NULL,
      [AutologSort] [tinyint] NULL,
      [GradeFamilly] [int] NULL)
  </code></pre>