title: Many to one join help for flat file
body: <p>I’m not sure if this has already been asked – I looked around for quite a bit but couldn’t find anything.</p>
  
  <p>My end result is to get data from several of my SQL database tables into a comma delimited flat file. Normally this would not be a problem but due to their many to one relationship and the format I’m forced to put it in it’s proving to be.</p>
  
  <p>1st I’ve got one table, the Report table which has all basic info for a report. For example</p>
  
  <pre><code>CREATE TABLE tblReportExample
  (
      ReportID int,
      ReportMonth smalldatetime,
      ReportDetails varchar(500)
  )
  </code></pre>
  
  <p>2nd I’ve got another table with cases for each report.</p>
  
  <pre><code>CREATE TABLE tblReportCasesExample
  (
      ReportID int,
      ReportCase varchar(50)
  )
  </code></pre>
  
  <p>3rd I have a flat file definition with the following:</p>
  
  <p>ReportID,
  ReportMonth,
  ReportDetails,
  ReportCase1,
  ReportCase2,
  ReportCase3</p>
  
  <p>What I need to do is add take the top three cases from the tblReportCasesExample for a report, join it somehow with the data in tblReportExample and add it to the flat file as ReportCase1, 2 and 3.</p>
  
  <p>I’ve been looking at this thing all day and just can’t figure it out.</p>
  
  <p>Any ideas?</p>