title: ASP Retrieving database records, and then retrieving more records from another table using the first records
body: <p>bit of a weird one. I have got a table in a database that stores ID's for records in another table. I need to retrieve and somehow store the information from table1. </p>
  
  <p>Information:
  Product, Image ID, Quantity</p>
  
  <p>So the Image ID will be the ID of the record in table2. Which I will then use to get that record. With that record I will find the save location of the image, and write the image onto the document the same number of times that is stored in the quantity value for that product. </p>
  
  <p>Hope you understand how I need this to work. Here is some example data. </p>
  
  <pre><code>-Product 1-
  Product -&gt; "KR"
  Image ID -&gt; 772
  Quantity -&gt; 2
  
  -Product 2-
  Product -&gt; "KR"
  Image ID -&gt; 774
  Quantity -&gt; 5
  
  -Product 3-
  Product -&gt; "LR"
  Image ID -&gt; 776
  Quantity -&gt; 1
  </code></pre>
  
  <p>Now using the above data, get data from table2 using the Image ID as the rows Unique ID and store the save location. </p>
  
  <p>This is what i'm trying at the moment, but it doesn't seem to work. </p>
  
  <pre><code>&lt;!--#include virtual="nightclub_photography\asp\functions.asp"--&gt;
  &lt;%
  'Connect to database
  set conn=Server.CreateObject("ADODB.Connection")
  conn.Provider="Microsoft.ACE.OLEDB.12.0"
  conn.Open Server.MapPath("/nightclub_photography/data/database/jamsnaps.mdb")
  
  'Get the current date
  today = ISODate(Request.Cookies("sdate") &amp; " 00:00:00")
  
  'Query the database for sales
  sql = "SELECT * FROM sales WHERE DATEVALUE(saleDate) = " &amp; today &amp; " AND printed = 0 ORDER BY product"
  Set rs = conn.Execute(sql)
  
  Set sales = Server.CreateObject("Scripting.Dictionary")
  
  if rs.EOF then
      response.write "No sales found!"
  else
      do until rs.EOF
          'response.write rs("product")&amp;":"&amp;rs("quantity")&amp;", "
          if sales.Exists(rs("product")) then
              sales.Item("product") = ","&amp;rs("jpgId")&amp;":"&amp;rs("quantity")
          else
              sales.Add rs("product"), rs("jpgId")&amp;":"&amp;rs("quantity")
          end if      
  
          'Move to next sale
          rs.MoveNext
      loop
  end if
  
  rs.close
  conn.close
  %&gt;
  </code></pre>
  
  <p><strong>Update 1</strong>
  Getting an error, simplified it a bit for now, just want to get it getting some results first. </p>
  
  <p>Error:
  <code>Type mismatch in expression.</code></p>
  
  <p>Query:
  <code>sql = "SELECT * FROM images WHERE ID IN (SELECT jpgId FROM sales WHERE printed = 0)"</code></p>
  
  <p>So, using the jpgId from row numbered "2." will return the row with the same ID labeled "1.". It will do this for each sale row. </p>
  
  <p><img src="https://i.stack.imgur.com/dt81n.jpg" alt="See image"></p>