title: Copy multiple files into one with xp_cmdshell with variable path using SQL
body: <p>I've created some csv files using bcp in Sql Server 2008. Now I need to merge those files into one. It works if I define explicitly the path of the files but if I declare it it tells me that it can not find the files.</p>
  
  <p>declare @variable_path_file1 = "c:\file.csv"
  declare @variable_path_file2 = "c:\file2.csv"</p>
  
  <p>it works like this:</p>
  
  <pre><code>exec master..xp_cmdshell 'copy /b "c:\file.csv" + "c:\file2.csv" "C:\result.csv"'
  </code></pre>
  
  <p>But it doesnt work like this:</p>
  
  <pre><code>exec master..xp_cmdshell 'copy /b @variable_path_file1 + @variable_path_file2 "C:\result.csv"'
  </code></pre>
  
  <p>Nor like this:</p>
  
  <pre><code> exec master..xp_cmdshell 'copy /b '@variable_path_file1' + '@variable_path_file2' "C:\result.csv"'
  </code></pre>
  
  <p>Neither like this:</p>
  
  <pre><code> exec master..xp_cmdshell 'copy /b "'@variable_path_file1'" + "'@variable_path_file2'" "C:\result.csv"'
  </code></pre>
  
  <p>Can someone help me, please?</p>