title: Passing SubQuery into OpenQuery with AS400 Linked Server
body: <p>I have a Linked Server to the AS400 here.  I'm trying to pull data from a field, but it is pulling over a  million records when I only need about 20k.</p>
  
  <p>I have a list of IDs that I need, and I'm trying to figure out how to pass that list into the OpenQuery.</p>
  
  <p>Here is my OpenQuery:</p>
  
  <pre><code>SELECT * FROM OPENQUERY(AS400, '
      SELECT 
          IMITNO, IMITD1, IMITD2, IMMFNO, IMBMTP, IMDSCO 
        FROM AS400.APLUS2FLE.ITMST 
        WHERE IMDSCO != ''Y''
  ')
  </code></pre>
  
  <p>I want to add <code>WHERE IMITNO IN (SELECT item_id FROM as400_item_scope)</code> but the as400_item_scope table is on the SQL machine, not the AS400.  I looked at several examples and I can pass in a single variable, but I don't understand how to pass in a list/query like this.</p>
  
  <p>I'm using latest SSMS, but SQL Server Version is 2008</p>