Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:46:07+00:00 2026-05-17T15:46:07+00:00

A csv file contains 8 columns (col1, col2, …, col8) and the name of

  • 0

A csv file contains 8 columns (col1, col2, …, col8) and the name of the file contains the date which has to be inserted into the table as well.

If the number of columns in the table and columns in the csv file are equal the following query imports all the records from the file to the table:

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

So far I haven’t found a solution to modify the query such that the new records can contain the date extracted from the filename. Anyway I have created a function to extract the date:

DateTime eventTime = extractDate(path);

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

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

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:46:07+00:00Added an answer on May 17, 2026 at 3:46 pm

    You cannot add an “arbitrary column” to the data set being loaded with the BULK INSERT command. (SSIS packages can do that, if you want to deal with their complexity.)

    The following trick is a bit complex, but I’ve used it succesfully several times:

    • Determine the name of the extra column and the value to load into it (say, MyDate and ‘Jan 1, 1980’)
    • Create a (temporary) default on the table based on that (ATLER TABLE MyTable add constraint DF_TempLoad default ‘Jan 1, 1980’ for MyDate [check the syntax, it may be off]
    • Create a (temporary) view on the table, listing only those columns to be bulk inserted
    • Run the BULK INSERT against the view; the column not included in the view will be assigned the default value
    • Drop the view
    • Drop the default constraint.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file which contains an ID and several other columns. I
I have a csv file which has two columns, a numeric ID ( IDVAR
I have a .csv file that contains data for only certain columns in a
I have a Testing project that contains a csv file which a webtest uses
I have a CSV file which has the following format: id,case1,case2,case3 Here is a
I have a CSV file that contains over 80,000 rows and 100 columns. I'm
I have an Excel (or CSV) file that contains the following flattened columns: ID,XPath,Required?,BaseType,Restrictions
I have a CSV file which contains data seperated with tabs. I need to
I have a CSV file, which contains three dates: '2010-07-01','2010-08-05','2010-09-04' When I try to
I have a csv file that has 2 columns separated by a comma -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.