Passing variable to Connection (ODBC connection)

Jack_881

New Member
Joined
Sep 11, 2020
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Hi Experts

I have a spreadsheet that connects to an external source using ODBC using the connection from the ODBC 64-bit App. This data source imports information based on the LOTID. Currently the only way I know to change the LOTID is to go into Power Query Editor and click Source which shows the SQL statment being used to retrieve the data. I manually change the WHERE statment to the LOTID that I want to import.

Whilst this works, I would rather be able to pass a variable to the Connection and it either changes the LOTID in the SQL statment or just imports the entire SQL statment including the new LOTID. The only thing that changes in the SQL statement is the LOTID. Example:

Select
Reports.*,
Lots.Customer,
Lots.Description

FROM
Units_Reports Reports

INNER JOIN

Lots ON Reports.LotID = Lots.LotID

WHERE Reports.LotID = 1238

Not sure if an elegant solution is possible.

Cheers

Jack
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Watch MrExcel Video

Forum statistics

Threads
1,127,082
Messages
5,622,581
Members
415,909
Latest member
vbaBeginner94

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
Top