title: Filtering table based on customerID and closest transaction date to unique dates
body: <p>Using Microsoft SQL Server Management Studio I am accessing a SQL Server table (<em>TransHistory</em>) that contains <strong>CustomerID</strong> and <strong>TransactionDate</strong> as my two fields of interest. Separately I have a list of <strong>CustomerIDs</strong> and <strong>Dates of Interest</strong> in an excel spreadsheet. I am trying to query the list of customers from excel spreadsheet in <em>TransHistory</em> where it outputs the closest past <strong>TransactionDate</strong> to the Date of Interest for that <strong>CustomerID</strong>.</p>
  <p><em>TransHistory</em> has hundreds of thousands of customers+transactions for which I'm querying for about a thousand customers and only need 1 unique row per customer. The <strong>Dates of Interest</strong> are unique to each customer (example entries from spreadsheet below) and won't always match the <strong>TransactionDate</strong> in <em>TransHistory</em> table, which is why I am querying for the closest past date to the <strong>Date of Interest</strong>.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>CustomerID</th>
  <th>Date of Interest</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>11111</td>
  <td>1/21/2022</td>
  </tr>
  <tr>
  <td>22222</td>
  <td>2/28/2013</td>
  </tr>
  <tr>
  <td>33333</td>
  <td>5/13/2018</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The thing is I know how to do it in a multistep process of first querying all data in <em>TransHistory</em> for my <strong>CustomerIDs</strong> and then doing a subsequent query to then filter for the <strong>Date of Interest</strong>. When trying to simply/combine it into 1 query I get stumped by the fact that <strong>Date of Interest</strong> is unique to each <strong>CustomerID</strong>.</p>
  <p>Would it be possible to filter for <strong>CustomerID</strong> while also filtering for <strong>CustomerID</strong> specific <strong>Dates of Interest</strong> in the same query? I am thinking it will require a two-dimensional array as a where statement, but I've never worked with them and not sure how to begin setting this up.
  Would appreciate being pointed in the right direction. Thanks!</p>