title: ASP.NET pass SQL statement to run in SQL Agent job
body: <p>Because it takes too long to export > 5 million cells to excel in my ASP.NET page, I have decided to run a SQL Agent job in the background instead and send the excel file link to the user's email inbox. </p>
  
  <p>My question is how do I pass the SQL statement (which changes depending on user selection on ASP.NET page) to run to the SQL agent job? Do I need to create a stored procedure first? Then get the SQL Agent job to run the sp?</p>
  
  <p>Also, how do I export the SQL result into a CSV file using the SQL Agent Job?</p>
  
  <p>Thanks!</p>