If you have a lot of data in CSV or Excel file, you may want to insert them into SQL table. In this lesson, I’ll teach you how you can do it with a formula.
The following example has four columns with data. We want to insert it into an SQL table.
Now we are going to add the following formula to cell E2 and autofill for the rest of the rows.
Instead of using single quotes and double quotes, we are going to use only double quotes. In this case, if you need to insert a string value (first_name, last_name) you can use double quotes three times. This way, we are sure that there is no conflict between quotes.
1 |
="INSERT INTO Person(id,first_name,last_name,age) VALUES ("&A3&", """&B3&""", """&C3&""", "&D3&");" |
After you use autofill, it’s going to return three SQL queries.
1 2 3 |
INSERT INTO Person(id,first_name,last_name,age) VALUES (1, "John", "Brown", 45); INSERT INTO Person(id,first_name,last_name,age) VALUES (2, "Jack", "Stevenson", 23); INSERT INTO Person(id,first_name,last_name,age) VALUES (3, "William", "Lee", 65); |