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 7888847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:56:29+00:00 2026-06-03T05:56:29+00:00

Through my ASP.NET / SQL Server 2008 app I need to do a bulk

  • 0

Through my ASP.NET / SQL Server 2008 app I need to do a bulk insert of records from a CSV file (maybe a million records). I will import them into a staging table first, so I can manipulate some of the data before moving it to a permanent table.

This will happen on a regular basis. And multiple imports may happen simultaneously. I also have to tell each import from the others.

My original plan was to use a column that had an Import_ID in it. But I see that Bulk Insert won’t allow me to set a field value.

Doing a search, I see that I can do a Bulk Insert into a view. And I’m guessing that the view can have a named parameter (Import_ID). But I haven’t really learned setting up parameters yet, so I don’t know if this is possible, or how to do it.

Can someone please tell me how to do this, or let me know another solution?

Thanks

  • 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-06-03T05:56:31+00:00Added an answer on June 3, 2026 at 5:56 am

    You could bulk insert into a temporary staging table, for example since you know your SPID (and assuming you can trust the schema of some static table) you can say something like this, specifying the @filepath for the CSV file and the @ImportID, creating a table with your session id as a suffix, and doing all your work in a single dynamic SQL batch:

    DECLARE @sql NVARCHAR(MAX), @spid VARCHAR(12) = RTRIM(@@SPID);
    
    SET @sql = N'SELECT * INTO dbo.Stage' + @spid 
        + ' FROM dbo.RealStagingTable WHERE 1 = 0;';
    
    SET @sql += N'BULK INSERT dbo.Stage' + @spid + ' FROM ('''
        + @filepath + ''' WITH (options);'
    
    SET @sql += N'INSERT dbo.RealTable(ImportID, other columns)
      SELECT ' + RTRIM(@ImportID) + , other columns
      FROM dbo.Stage' + @spid + ';';
    
    SET @sql += N'DROP TABLE dbo.Stage' + @spid + ';'
    
    EXEC sp_executesql @sql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cached one DataTable fetched from SQL Server 2005 through C# ASP .NET 4.0
when i'm inserting data to the sql server 2008 database through asp.net application date
Through an C#/ASP.NET website, I'm using SpreadsheetGear to open a file from a template,
We've an ASP.Net MVC2 web app (SQL 2008 in backend). We use Data Annotations
using asp.net, sql server 2008, winserver2003 we have about 10 tables with about 20
I am writing and ASP.NET MVC application with SQL Server 2008. Unfortunately, the only
I have an ASP.NET MVC Web Application that interacts with a SQL Server 2008
I am trying to connect to SQL server through an asp.net page and I
I am calling the SQL Server Reporting Services Webservice from inside an asp.net application.
I have recently moved our ASP.NET session state from InProc to a Sql Server

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.