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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:38:33+00:00 2026-06-03T00:38:33+00:00

I am trying to determine how to import some CSV data into a MS

  • 0

I am trying to determine how to import some CSV data into a MS SQL database.

Unfortunatly it is not as simple as it sounds, since more then one table is involved. Also some of the fields will be pulled from the CSV, while others will have fixed values.

In terms of relating multiple tables, my logic would be as following:

IF <select count(course_name) from tbl_courses WHERE course_name = 'value from csv'> GT 0
THEN
  ADD <data> to TBL_ITEM using PK from TBL_COURSES
ELSE
  CREATE ROW in TBL_COURSES WITH <data>
  ADD <data> to TBL_ITEM using PK from TBL_COURSES
END IF

Is there a way to map the fields in my CSV to the tbl_item (while adding a row to tbl_courses as needed?)

  • 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-03T00:38:34+00:00Added an answer on June 3, 2026 at 12:38 am

    Basically you want to start thinking set based and carry out the following steps:

    1. Import your CSV in to a temporary table.

    2. Insert into your courses table selecting from your temp table, you can include your static data as well but make sure to distinct to ensure duplicate entries aren’t made.

    3. Insert into your items table selecting from your temp table, including the course tables PK will depend on your CSV data. If you already have the unique course id as part of the CSV data then great, otherwise you can sub query as part of the insert.

    Here’s an example of what I’m trying to explain if it helps, obviously courseData and itemData is really your set of fields…

    -- setup for example
    declare @course table (courseId int, courseData varchar(50))
    declare @item table (itemId int, courseId int, itemData varchar(50))
    
    declare @csvdata table (courseid int, coursedata varchar(50), itemid int, itemdata varchar(50))
    
    insert into @csvdata 
    values (1, 'a', 1, 'b'), (1, 'a', 2, 'c'), (2, 'b', 3, 'c')
    
    -- the important bit
    insert into @course
    select distinct courseId, courseData
    from @csvdata
    
    insert into @item
    select itemId, courseId, itemData
    from @csvdata
    
    select * from @course
    select * from @item
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to import data from a mySQL database into Microsoft SQL because
I'm trying to import a csv file into SQL using SSIS and am hitting
I am trying to determine which implementation of the data structure would be best
We're trying to determine how to implement a simple plugin framework for a service
I'm trying to import a cvs module into an existing git repo. I can
I am reading hundreds of CSVs to import into a DB. Some of the
I'm trying to diff two strings to determine whether or not they solely vary
I've been trying determine the uncompressed size of a compressed database dump. I've been
Hi I'm trying to import a shape file from http://www.nyc.gov/html/dcp/html/bytes/bytesarchive.shtml into a postgis database.
I'm uploading a csv from a form. I'm trying to use mysql_affected_rows to determine

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.