title: Generating a .csv file by running a .sql script with osql.exe
body: <p>I have a script file in a folder.I want to use TSQL to run this script without opening it in SSMS as I will be using SSIS to run this script to generate CSV.</p>
  
  <p>I have used OSQL to achieve this by using Execute Process Task but it is not giving me exact results I am looking for. It is generating spaces in the csv. A 17 mb file which I exported by rightclick as CSV option turned out to 1gb when I executed using OSQL code.The OSQL I used is:</p>
  
  <p><code>-E -S CCCMSDSQL20,1819 -d SHARE_SCRUB  -q  "SET NOCOUNT ON" -i "C:\Scripts\.SQL" -o "C:\Scripts\.csv" -n -h-1 -s"," -w 700</code></p>
  
  <p>I prefer a TSQL script which can achieve the same,so that I can use it in Execute SQL task and get the results.</p>
  
  <p>EDIT:
  I am working to generate multiple csv's from multiple .sql files in a folder .I am using a for each loop container and execute process task as of now.I want to change the execute process task to execute sql task and use this script to generate multiple files.</p>
  
  <p>If it is possible to write a TSQL code which can do the looping and generation of CSV files in one script I can use it without using the package.</p>
  
  <p>Thanks for your time and help.</p>