title: How to make SQL Server Agent job write to a file?
body: <p>I need to deliver a stored procedure to a client, who will set up a scheduled job to output to a file. The client thinks the stored procedure should write to the file, but I'm surprised that I can't just produce a table and ask their DB admin to set up the job so the output goes to a file.</p>
  
  <p>The file has to conform to a specific format for import into another system.</p>
  
  <p>I have a query SELECT (code for header) UNION ALL SELECT (code that creates a string for each entry) UNION ALL SELECT (code for footer).</p>
  
  <p>The expression is rather complicated, and I don't want to cram it all into a BCP string argument. </p>
  
  <p>What is the best way to do this? Can BCP call a stored procedure? Can the SQL Job description "redirect" output to a file? Should I create a temp table and point BCP at that?</p>