在VBA Excel中查询SQL

问题描述

我将我的excel连接到MS sql,我希望执行该查询

inference_output = sess.run(output,{args: args_numpy})

及其工作正常

我想在vba上使用它:

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

现在如何在查询中设置VAR: 国家/地区城市,例如range(“ A1”)。value或将变量dim city声明为字符串。

解决方法

例如:


Dim country,city

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

Set rs = c.Execute("SELECT * FROM Customers " & _ 
                   " WHERE Country='" & country  & "'" & _
                   " AND City='" & city & "'")