-1

i connect my excel to MS SQL and i want excute the query :

SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='München');

and its work fine

i want use it on vba:

Set rs=c.Execute(“SELECT * FROM Customers" & _ 
WHERE Country='Germany' AND (City='Berlin' OR City='München');”)"

now how can set VAR inside the query: Country and City something like range("A1").value or declare variable dim city as string.

Salim Fh
  • 75
  • 6
  • Does this answer your question? [Tricks for generating SQL statements in Excel](https://stackoverflow.com/questions/315504/tricks-for-generating-sql-statements-in-excel) – nbk Nov 07 '20 at 23:55

1 Answers1

0

E.g. :


Dim country, city

country = Range("A1").Value
city = Range("B1").Value

Set rs = c.Execute("SELECT * FROM Customers " & _ 
                   " WHERE Country='" & country  & "'" & _
                   " AND City='" & city & "'")
Tim Williams
  • 154,628
  • 8
  • 97
  • 125