title: how to export sql data to csv using bcp
body: <p>I use simple code</p>
  
  <pre><code>declare @sql varchar(8000) 
  select @sql  = 'bcp ExcelAnalysis.dbo.ClearDB out c:\csv\comm.txt -c -t, -T -S '+ @@servername 
  exec master..xp_cmdshell @sql 
  </code></pre>
  
  <p>but this code export all my table, but i need only some fields and conditions
  like:</p>
  
  <pre><code>declare @sql varchar(8000) 
  select @sql = 'bcp 
  SELECT 
  
        ,[vl]
        ,[data]
        ,[URL]
        ,[parse]
        ,[Strata]
        ,[Id]
     FROM [ExcelAnalysis].[dbo].[ClearDB] where [data]&gt; "01.05.2017" and NOT [vl] ="mag"and NOT [vl] ="Maxximo"   out c:\csv\status.txt -c -t, -T -S '+ @@servername 
  exec master..xp_cmdshell @sql 
  </code></pre>
  
  <p>but if i use any fields, the bcd returns message with his syntax.
  How do correct?</p>