title: BCP command execute each row SQL Command in Table
body: <p>I had write a procedure that export each of the SQL Query data to the csv file with header.
  But I dont know the error shown as below.</p>
  <blockquote>
  <p>Msg 512, Level 16, State 1, Line 26
  Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , &gt;, &gt;= or when the subquery is used
  as an expression.
  Msg 512, Level 16, State 1, Line 27
  Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , &gt;, &gt;= or when the subquery is used
  as an expression.</p>
  </blockquote>
  <p>Here with my sample database</p>
  <p><a href="https://i.stack.imgur.com/kDjJE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kDjJE.png" alt="enter image description here" /></a></p>
  <p>Here with my Code</p>
  <pre><code>DECLARE @SQLCmd varchar(max)
      DECLARE @FilePathCmd varchar(max)
      DECLARE @ExportCmd varchar(max)
  
      SET @SQLCmd=(SELECT CommandText from TestDB.dbo.CommandExportData)
      SET @FilePathCmd=(SELECT FilePath from TestDB.dbo.CommandExportData)
  
      
  
     SELECT @ExportCmd='bcp &quot;'+@SQLCmd+'&quot; queryout &quot;'+@FilePathCmd+'&quot; -c -t, -T -S' + @@servername
     print(@ExportCmd)
     exec master..xp_cmdshell @ExportCmd
  </code></pre>