Often when you are working on 2 incompatible systems and try to import data from one to another, excel can be a handy tool. I have used excel plenty of times to generate SQL insert / update statements which I could later execute on the database console. Here is a tutorial if you ever have to use excel to generate SQL statements.
The example below shows a simple insert statement generated from customer data in a table. But you can easily extend this technique to come up with complex query statements.
1. Have your data ready
For our purpose the data is arranged like this:
As you can see, the data has to be in a tabular format so that you can easily generate the query statements. Often you may have to use lookup formulas to clean up the raw data imported in CSV formats.
2. Using excel operator ‘&’ to generate SQL query
Once the data is ready it is very easy to generate the SQL queries using excel string addition operator – &. For the above tabular structure, the concatenate formula would look like:
="insert into customers values('" &B3 &"','" & C3 & "','"&D3&"');"
where B3, C3, D3 refer to above table data.
The final queries will look like:
There are a few practical ways to improve this:
- Cleaning up data using countif(), sumif(), if() formulas
- Using vlookup() or countif() to cross-reference items on one table to another
One Response to “How to compare two Excel sheets using VLOOKUP? [FREE Template]”
Maybe I missed it, but this method doesn't include data from James that isn't contained in Sara's data.
I added a new sheet, and named the ranges for Sara and James.
Maybe something like:
B2: =SORT(UNIQUE(VSTACK(SaraCust, JamesCust)))
C2: =XLOOKUP(B2#,SaraCust,SaraPaid,"Missing")
D2: =XLOOKUP(B2#,JamesCust, JamesPaid,"Missing")
E2: =IF(ISERROR(C2#+D2#),"Missing",IF(C2#=D2#,"Yes","No"))
Then we can still do similar conditional formatting. But this will pull in data missing from Sara's sheet as well.