title: SQL: Insert file name as value (using BULK INSERT)
body: <p>I am importing several CSV files into a single table (using <a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql?view=sql-server-2017" rel="nofollow noreferrer">BULK INSERT</a>). Each CSV file contains information about each department's computers, and are imported monthly into a truncated table.</p>
  
  <p>For billing purposes, I want to track which CSV file each row came from.
  Therefore, I'd like to add a column, specifying the file name of each imported file.</p>
  
  <p>Is there an elegant way to achieve this?</p>
  
  <p><em>I was thinking about copying the imported data to a second table, and then adding the column information in the process, and truncating the CSV import table after each iteration.</em></p>
  
  <p>I am using Microsoft SQL Server 2017.</p>
  
  <p>The SQL queries are currently:</p>
  
  <pre><code>CREATE TABLE Computere (
  Computernavn varchar(255),
  Serienummer varchar(255),
  Model varchar(255),
  OSVersion varchar(255),
  OSDBruger varchar(255),
  SenesteBruger varchar(255),
  SidsteLogon varchar(255)
  );
  
  BULK INSERT Computere
  FROM '\\server\share\file_for_each_department.csv'
  WITH
  (
      FORMAT = 'CSV', 
      DATAFILETYPE = 'char',
      FIELDQUOTE = '"',
      FIRSTROW = 2,
      FIELDTERMINATOR = ';',
      ROWTERMINATOR = '0x0a',
      CODEPAGE=65001 ,
      TABLOCK
  );
  </code></pre>