Volume sql insert with extra column

The csv file contains 8 columns (col1, col2, ..., col8), and the file name contains the date, which must also be inserted into the table.

If the number of columns in the table and columns in the csv file is equal, the following query imports all the records from the file into the table:

query += "BULK INSERT real_data FROM '" + path + "' WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')";

So far, I have not found a solution to change the request, so the new entries may contain the date extracted from the file name. Anyway, I created a function to retrieve the date:

DateTime eventTime = extractDate(path);

and would like to insert eventTime in the 9th column for each record imported from the file.

Does anyone know how to modify / create a query request to import 8 columns from a file and add a date as the 9th column for each imported record?

Thank!

+3
1

" " , BULK INSERT. ( SSIS , .)

, :

  • (, MyDate '1 1980 ).
  • () (ATLER TABLE MyTable DF_TempLoad '1 1980 MyDate [ , ]
  • () , , .
  • BULK INSERT ; , ,
  • .
+5

Source: https://habr.com/ru/post/1769139/


All Articles