You will need one query per different file sturcture.
See
https://learn.microsoft.com/en-us/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-ver16
for how to.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
SQL query to import multiple csv/txt files into SQL Server.
You will need one query per different file sturcture.
See
https://learn.microsoft.com/en-us/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-ver16
for how to.
Hi @nn
To import multiple csv/txt files into SQL Server using SQL query, you typically need two steps:
First, you need to list all files inside a folder to a table.
Then generate dynamic bulk insert query to import these files.
It is suggested to use SSIS to accomplish this, see this blog: SSIS - How To Load Multiple Files ( .txt or .csv ) To a Table With File Names.
Best regards,
Cosmog
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".