title: using BCP to export stored procedure result in SQL Server 2008
body: <p>Heyy,</p>
  
  <p>I'm trying to use BCP to export a SP result to a text file using this query:</p>
  
  <pre><code>EXEC xp_cmdshell 'bcp "exec asmary..usp_Contract_SelectByEmpId -1,1" queryout "C:\test.txt" -w -C OEM -t$ -T -r ~ -S heba\HEBADREAMNET '
  </code></pre>
  
  <p>The output of this query is telling this error:</p>
  
  <blockquote>
    <p>Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near the keyword 'where'.</p>
  </blockquote>
  
  <p>even thought I'm sure that the stored procedure "usp_Contract_SelectByEmpId" is working correctly.</p>
  
  <p>Anyone faced that kind of error before?</p>