Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tricks for generating SQL statements in Excel

Do you have any tricks for generating SQL statements, mainly INSERTs, in Excel for various data import scenarios?

I'm really getting tired of writing formulas with like

="INSERT INTO Table (ID, Name) VALUES (" & C2 & ", '" & D2 & "')"

like image 477
David Vidmar Avatar asked Nov 24 '08 21:11

David Vidmar


People also ask

Can you practice SQL in Excel?

Open an SQL connection to an Excel fileBefore running an SQL query, you have to open a connection with the Excel file you want to access. To establish the connection, create a new variable named %Excel_File_Path% and initialize it with the Excel file path.

How do I keep SQL query results automatically in Excel?

Open SQL Server Management Studio and connect to the database. 2. Go to "Object Explorer", find the server database you want to export to Excel. Right-click on it and choose "Tasks" > "Export Data" to export table data in SQL.


1 Answers

The semi-colon needs to be inside the last double quote with a closing paren. When adding single quotes around a string, remember to add them outside your selected cell.

(spaces added for visibility - remove before inserting)

=CONCATENATE("insert into table (id, name) values (",C2,",' ",D2," ');")

Here is another view:

=CONCATENATE("insert into table (id, date, price) values (",C3,",'",D3,"',",B3,");")

like image 114
Jason V Avatar answered Oct 07 '22 00:10

Jason V