title: t-sql return multiple rows depending on field value
body: <p>i am trying to run an export on a system that only allows t-sql. i know enough of php to make a foreach loop, but i don't know enough of t-sql to generate multiple rows for a given quantity.
  i need a result to make a list of items with &quot;1 of 4&quot; like data included in the result</p>
  <p>given a table like</p>
  <pre><code>orderid, product, quantity
  1000,ball,3
  1001,bike,4
  1002,hat,2
  </code></pre>
  <p>how do i get a select query result like:</p>
  <blockquote>
  <p>orderid, item_num, total_items,
  product</p>
  <p>1000,1,3,ball</p>
  <p>1000,2,3,ball</p>
  <p>1000,3,3,ball</p>
  <p>1001,1,4,bike</p>
  <p>1001,2,4,bike</p>
  <p>1001,3,4,bike</p>
  <p>1001,4,4,bike</p>
  <p>1002,1,2,hat</p>
  <p>1002,2,2,hat</p>
  </blockquote>