Sometimes, we need to read an external CSV file using T-SQL query in SQL Server. Due to some functional limitations, we cannot use the import-export wizard functionality in such kinds of scenarios as we need the result set in the middle of the execution of the other queries. There, we can use the BULK INSERT SQL command which helps us to import a data file into SQL Server table directly.
Let’s have a look at the sample CSV file which we want to import into a SQL table. The CSV file is this.
To download the sample CSV file, click here. The above CSV file uses comma as a column delimiter and contains 6 columns which are:
PersonID – Stores the Id of the person.
FullName – Stores the full name of the person.
PreferredName – Stores the preferred name of the person.
SearchName – Stores … More