title: SQL query to export single data row to multiple CSV rows
body: <p>We are trying to automate some steps and I need to setup a query to dump data on a schedule. The problem I am having is taking the single row of data from the SQL table and dumping it to multiple rows of data.
  The SQL table is used for a parts order form and has fields for up to 10 parts to be entered (Part01 - Part10) and fields for quantities of each part (Qty01-Qty10). As in most orders, we are not using all 10 lines on every order, so when we export, we also need to test if there is data in the part field (PartXX&lt;>'') to only generate rows for lines that actually have data. There are also fields in the table that would need to be populated in each output row, even though it doesn't change. The query for the first "row" is straight-forward, but my obstacle is the "IF/THEN" part for the subsequent rows and generating the "Line" for the </p>
  
  <p>The output I am looking for is like this:</p>
  
  <pre>Ticket# CustID  Account  Line  ShipAttn  ShipAdd  ShipCity ShipState  ShipZip  Part Qty
  123456  Cust01  987465   1     Joe Smith Address  AnyTown  IL         01234    Key  2
  123456  Cust01  987456   2     Joe Smith Address  AnyTown  IL         01234    Lock 2</pre>
  
  <p>Any direction is appreciated.</p>