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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:35:59+00:00 2026-05-15T16:35:59+00:00

I have a need to import a number of CSV files into corresponding tables

  • 0

I have a need to import a number of CSV files into corresponding tables in SQL. I am trying to write a stored procedure that will import any of these CSV files, using a number of parameters to set things like file name, destination name etc.

Simple so far. The problem comes because of the structure of this DB. Each data table has a number of (usually 5) columns that are of a set format, and then however many data columns you want. There are then a set of data validation tables that contain specific sets of values that these 5 columns can contain. So the problem is, is that when I do the import from CSV, I need to validate that each row that is imported meets the criteria in these validation tables, essentially that there is a row in the validation table that has data that matches the 5 columns in the imported data.

If it does not, then it needs to write an error to the log and not import it, if it does then it should import it.

Here is an example of what I mean:

Data Table (where the imported data will go)

|datatype|country|currency| datacolumn1 | datacolumn|
|1       | 2     |  GBP   | 10000       | 400       |
|3       | 4     |  USD   | 10000       | 400       |

Validation table

|datatype|country|currency|
|1       |2      |GBP     |
|2       |3      |USD     |

So the first line is valid, it has a matching record in the validation table for the first 3 columns, but the second is not and should be rejected.

The added problem is that each table can reference a different validation table (although many reference the same one) so the columns that have to be checked often vary in amount and name.

My first problem is really how to do a row by row check when importing from CSV, is there any way to do so without importing into a temporary table first?
After that, what is the best way to check that the columns match, in a generic way despite that fact that the name and number of columns change depending on what table is being imported.

  • 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-15T16:36:00+00:00Added an answer on May 15, 2026 at 4:36 pm

    You can import the contents of a csv into some temporary tables by using this –

    SELECT * into newtable FROM
    OPENROWSET ('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir={Directory Path of the CSV File};', 
    'SELECT * from yourfile.csv');
    

    Once you have your data in some sql table, you can use an inner join to validate the data and narrow down to the valid rows.

    SELECT A.*,B.* FROM newtable A
    INNER JOIN validation_table B ON A.Datatype = B.Datatype
    INNER JOIN validation_table C ON A.Country = C.Country
    INNER JOIN validation_table D ON A.Currency = D.Currency
    

    This should give you the valid rows according to your validation rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large number of csv files that I want to read into
I have an Excel file that I need to import into a (new) Oracle
I need to import a .csv file into a SQL table. The input file
I have some tables in Access that I'm trying to export to csv so
I have a CSV file listing items that I need to store within the
I'm using csv files to store the large number of variables I need for
I need to write a gui in Tkinter that can choose a csv file,
I have a list of numbers and I need to split into to corresponding
I have a long ID number (say, 12184447992012111111). BY using proc import from csv
So I have this need to import (currently) about 15k products. Each product has

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.