title: How can I save the results of an OPENQUERY query to an Excel or CSV file?
body: <p>How to store data from an openquery in a .CSV OR EXCEL FILE?</p>
  
  <pre><code>select * from openquery(DB_LINK,'SELECT col1,col2,col3,col4 from oracle_table_name')
  
  select * from openquery(DB_LINK,'SELECT col1,col2,col3,col4,col5 from oracle_table_name2')
  </code></pre>
  
  <p>The result has to be stored in 2 different files.</p>
  
  <p>I have scheduled the open query such that it runs on 1st of every month.
  And the 2 files that are generated have to be kept in client's windows specific folder.</p>
  
  <p>This is the first time I'm using SQL SERVER. So please explain step by step.</p>
  
  <p>I am using this query at the moment.</p>
  
  <pre><code>declare @title varchar(55) 
  set @title = 'Test'   
  
  EXEC sp_makewebtask 
    @outputfile = 'D:\Test11.xls', 
    @query = 'select CIRCUIT_DESIGN_ID as [Account Number] from openquery(MSP_PROD,'select CIRCUIT_DESIGN_ID from circuit')',
    @FixedFont=0,@resultstitle=@title
  </code></pre>