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 & "')"
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.
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.
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,");")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With