title: How to pass parameter to a bcp command in sql server
body: <p>I want to send a query result to a file, so tried to use bcp command. But can't pass any parameters to that. It shows error.</p>
  
  <pre><code>EXEC xp_cmdshell 'bcp "SELECT * FROM CG.dbo.cdyy where EndTime between     DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,'+@date+'),0)) and DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,1,'+@date+')+1,0))  " queryout "D:\cdr_cg.txt" -T -c -t,'
  </code></pre>