The simplest way to do what you describe it to import the CSV into a "staging" table, and then write TSQL to do what you need to do.
How to insert data from a .csv file and join it to two other tables and create an insert into the two tables script.
I have a .csv that has 4 columns that I need to insert data from two of those columns into two different tables. Two of those columns I need to join to two different tables to do insert statements into the two tables. Anyone know how to do this?
3 answers
Sort by: Most helpful
-
-
Erland Sommarskog 115.1K Reputation points MVP
2020-12-24T16:31:57.787+00:00 Yes, as Tom says, for a solution without SSIS (which I don't know myself), you need to import the file into a table, and then work from the table.
If the file is located so that you can access it from SQL Server, you can use the BULK INSERT command.
If it is not, you may be able to import it with the command-line utility BCP.
We also need which version of SQL Server you are using. What's the output of "SELECT @@version"?
-
Monalv-MSFT 5,901 Reputation points
2020-12-25T06:47:53.903+00:00 Hi @MR BILL ,
- Could you please share the example data in your .csv file and your desired output data?
- May I know if you installed the SQL Server Data Tools (SSDT) for Visual Studio ?
If so, please create new Integration Services project and package.
- Then we can drag a Data Flow Task in ssis package. We can use Flat File Source, Multicast Transformation and OLEDB Destination in Data Flow Task to load data from a .csv file to two sql tables.
Best Regards,
Mona----------
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues in November--What can I do if my transaction log is full?
Hot issues in November--How to convert Profiler trace into a SQL Server table?