0

I am trying to write a macro that queries the SQL database but enters a condition into the query. That condition is a range of values in a column in the spreadsheet.

So, I have "Sheet1", where column A is titled "code" with values from A2 onwards. I want to run a SQL query that says:

SELECT value FROM dbtable WHERE code = 'ValueFromA2'

With the result being populated in cell B2.

I then need to continue that query down through B3, B4, etc. until it's reached the end of the range of values in column A.

Is this possible?

1 Answer 1

0
  1. Use Excel to create list of queries into the new column by concatenating your SQL logic with "code" values.

    See this example: https://stackoverflow.com/a/16819629/327165

  2. Use VBA to loop thru column with SQL queries and populate results into column B. As an option you can create queries in VBA.

    See this example: SQL query in VBA, code stored in several cells in Excel

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.