Link to home
Start Free TrialLog in
Avatar of CiciO
CiciO

asked on

Using a Cell Reference in a SQL Query

I can't believe this is so hard.  I think I've seen 100 answers on EE to this exact question and I still can't figure it out.

I have a SQL Server database with a table called Branches.  I want to type a branch number into cell B7 of my spreadsheet and have Excel go out to SQL Server and get all of the information for the specified branch.

In Excel I went to Data > Import External Data > New Databse Query
I found the table.
I was able to create the following SQl... select * from "Autopart"."dbo"."Branches" where branch = '2024'

The problem is that I had to hard code the value 2024 when I really want it to look at cell B7 and use whatever value it finds.

I know nothing about VBA or ADO.

From everything I've read it seems quite doable, I just can't figure it out.

Does anybody have any "dummy" level instructions that might help me?

...timmy
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CiciO
CiciO

ASKER

Brilliant.  I shall name my next born child "Kevin".

I knew there had to be an easy way.

Thank you Thank you Thank you.

...timmy
You're welcome :-)

Kevin
This has helped me a lot at work where we are using dual database and spreadsheet systems.

You would have thought this would be a standard feature in Excel!!

Thank you very much :-]
There is a problem with this approach, when you close your spreadsheet (and save) then reopen, the cells are not saved in the parameter dialog box, and you have to reenter them all over again.... has anybody found a solution to this?