title: Importing to sql from csv in changing order of columns
body: <p>I'm using SQL 2012. I would like to create a stored procedure in SQL that would delete a table and then create one based on an import from a csv file. Simple enough so far. </p>
  
  <p>The issue is that the columns in my CSV file will probably be changing in order, due to some issues that are out of my control. I plan on identifying the columns with a name that will be linked to another name in a table as well (again, out of my control). </p>
  
  <p>For example (in CSV): </p>
  
  <pre><code>Name1           Name2      Name3
  1                3           2
  22               4           3
  3                13          12
  41               8           1
  22               6           4
  </code></pre>
  
  <p>In metadata table: </p>
  
  <pre><code>Names         ID      
  Name1         ID1           
  Name2         ID2           
  Name3         ID3         
  </code></pre>
  
  <p>And the table I want to create via import: </p>
  
  <pre><code>ID1           ID2      ID3
  1             3         2
  22            4         3
  3             13        12
  41            8         1
  22            6         4
  </code></pre>
  
  <p>The issue being that the names of the columns won't always be in the same order, any given day I could be given a CSV that would look like this: </p>
  
  <pre><code>Name3         Name2        Name1
  2               3           1
  3               4           22
  12              13          3
  1               8           41
  4               6           22
  </code></pre>
  
  <p>How would you go about naming via something like an inner-join, the columns in the table?</p>