Using cell values in SQL (MS Query)

  • Thread starter Thread starter Arshavir Grigorian
  • Start date Start date
A

Arshavir Grigorian

Hi,

Is there an easy way to use cell (or range) values in an MS Query SQL
- e.g. [select * from table where id = Cell("E4")]. TIA.
 
Add a prompt to your query so that it becomes parameterized.

select * from table where id = ?

Now exit the query and return to XL. If you select Data -> Import External
Data -> Parameters you will be able to assign the parameter to a cell.
 
Thanks. A couple of issues:

1) Can't do [ ... WHERE col IN (?)] Only allows single values.

2) Can't have a parameter in a query that can't be displayed
graphically.

Are these for real?



Add a prompt to your query so that it becomes parameterized.

select * from table where id = ?

Now exit the query and return to XL. If you select Data -> Import External
Data -> Parameters you will be able to assign the parameter to a cell.
--
HTH...

Jim Thomlinson



Arshavir Grigorian said:
Is there an easy way to use cell (or range) values in an MS Query SQL
- e.g. [select * from table where id = Cell("E4")]. TIA.- Hide quoted text -

- Show quoted text -
 
They are limitations of that approach. If you need more flexibility you
could use ADO directly.

Tim


Thanks. A couple of issues:

1) Can't do [ ... WHERE col IN (?)] Only allows single values.

2) Can't have a parameter in a query that can't be displayed
graphically.

Are these for real?



Add a prompt to your query so that it becomes parameterized.

select * from table where id = ?

Now exit the query and return to XL. If you select Data -> Import External
Data -> Parameters you will be able to assign the parameter to a cell.
--
HTH...

Jim Thomlinson



Arshavir Grigorian said:
Is there an easy way to use cell (or range) values in an MS Query SQL
- e.g. [select * from table where id = Cell("E4")]. TIA.- Hide quoted
text -

- Show quoted text -
 
When you are editing the query using the interface (not the wizard)
use square brackets with a space in between to create parameters.
These will enter the ?s in the SQL statement while the interface
writes SQL for you.

When you return to Excel, you'll be prompted for the parameters. You
can choose ranges (cells) for the parameters and tell it whether to
always look there for each parameter.

Cliff Edwards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top