SQL Queries in Excel

jenae

New Member
Joined
Jul 24, 2009
Messages
2
I have the following seven Access queries that I need to convert into an Excel macro because there is not a lot of data in the two source tables and my coworkers are more comfortable working in Excel than Access. I am not sure of how to write the VBA around these SQL queries so that it will run in Excel. The queries would basically sum up like lines on two different Excel tabs of data. Then it compares the two summaries against eachother to find any differences between the two data sets. The final query gives a list of the differences. Let me know if you need my example data.

Code:
[COLOR=#574123]Q1[/COLOR]
[COLOR=#574123]DELETE t1_FutCnvrtSumm.Contract_code[/COLOR]
[COLOR=#574123]FROM t1_FutCnvrtSumm;[/COLOR]

Q2
'INSERT INTO t1_FutCnvrtSumm ( Contract_code, Trade_Price, Buy_Sell, Lots )
'SELECT FutCnvrt.Contract_code, Round([Trade_Price],5) AS Trade_Pricerd, FutCnvrt.Buy_Sell, Sum(Round([LOTS],0)) AS Lots
'FROM FutCnvrt
'GROUP BY FutCnvrt.Contract_code, Round([Trade_Price],5), FutCnvrt.Buy_Sell;

Q3
'Delete t2_JPMData.Product
'FROM t2_JPMData;
   
Q4
'INSERT INTO t2_JPMData ( Product, [Buy_Sell], PRICE_CONVERTED, SumOfField48 )
'SELECT JPMData.Product, JPMData.[Buy_Sell], Round([PRICE_CONVERTED],5) AS PRICE_CONVERTEDrd, Sum(Round([Field48],0)) AS SumField48
'FROM JPMData
'GROUP BY JPMData.Product, JPMData.[Buy_Sell], Round([PRICE_CONVERTED],5);

Q5
'SELECT t2_JPMData.Product, t2_JPMData.[Buy_Sell], t2_JPMData.PRICE_CONVERTED, Sum(t1_FutCnvrtSumm.Lots) AS [SumOfLOTS ], Sum(t2_JPMData.SumOfField48) AS JPMDataTot INTO t5_data
'FROM t1_FutCnvrtSumm INNER JOIN t2_JPMData ON (t1_FutCnvrtSumm.Contract_code = t2_JPMData.Product) AND (t1_FutCnvrtSumm.Trade_Price = t2_JPMData.PRICE_CONVERTED) AND (t1_FutCnvrtSumm.Buy_Sell = t2_JPMData.[Buy_Sell])
'GROUP BY t2_JPMData.Product, t2_JPMData.[Buy_Sell], t2_JPMData.PRICE_CONVERTED;
  
Q6
'SELECT t1_FutCnvrtSumm.Contract_code, t1_FutCnvrtSumm.Trade_Price, t1_FutCnvrtSumm.Buy_Sell, t1_FutCnvrtSumm.Lots, t5_data.Product, "FutCnvrt" AS Name INTO t6_Not_In_Both
'FROM t5_data RIGHT JOIN t1_FutCnvrtSumm ON (t5_data.PRICE_CONVERTED = t1_FutCnvrtSumm.Trade_Price) AND (t5_data.[Buy_Sell] = t1_FutCnvrtSumm.Buy_Sell) AND (t5_data.Product = t1_FutCnvrtSumm.Contract_code)
'WHERE (((t5_data.Product) Is Null));
  
Q7
'INSERT INTO t6_Not_In_Both ( Contract_code, Buy_Sell, Trade_Price, Lots, Name )
'SELECT t2_JPMData.Product, t2_JPMData.[Buy_Sell], t2_JPMData.PRICE_CONVERTED, t2_JPMData.SumOfField48, "JPMData" AS Name
'FROM t2_JPMData LEFT JOIN t5_data ON (t2_JPMData.Product = t5_data.Product) AND (t2_JPMData.[Buy_Sell] = t5_data.[Buy_Sell]) AND (t2_JPMData.PRICE_CONVERTED = t5_data.PRICE_CONVERTED)
'WHERE (((t5_data.Product) Is Null));
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top