[英]query SQL in VBA excel
i connect my excel to MS SQL and i want excute the query :我将我的 excel 连接到 MS SQL,我想执行查询:
SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='München');
and its work fine它的工作正常
i want use it on vba:我想在 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.现在如何在查询中设置 VAR: Country和City 之类的 range("A1").value 或将变量 dim city 声明为字符串。
Eg :例如:
Dim country, city
country = Range("A1").Value
city = Range("B1").Value
Set rs = c.Execute("SELECT * FROM Customers " & _
" WHERE Country='" & country & "'" & _
" AND City='" & city & "'")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.