I am regularly required to compare data sent to me in Excel spreadsheets with data that lives in SQL Server. I know that you can connect SQL Server to spreadsheets but it always seemed clunky
This is really a post to show off my solution but I would love to hear other peoples ideas.
For best results, paste the below code into a module in your personal.xls file. You will need to add a reference to the Microsoft Forms 2.0 Object Library.
When you run this routine, it takes the currently highlighted region and creates an XML string. It also creates the TSQL to convert that XML into a temporary table called #tmp. It also pastes the TSQL into your clipboard. It makes a lot of assumptions and the default temporary table is all VARCHAR(100).
I bound this routine to Cntl-Shift-X.
The end result is if i highlight a reagion (with header), click Cntl-Shift-X, and past into a query window, I have immediate access to the spreadsheet data in SQL.
I’t has save me tons of time.
Recommendations for improvements are welcome :o)
As suggested, here’s an example. Consider this spreadsheet data:
This method will generate the following TSQL: