【问题标题】:query SQL in VBA excel在 VBA excel 中查询 SQL
【发布时间】:2023-03-17 17:54:01
【问题描述】:

我将我的 excel 连接到 MS SQL,我想执行查询:

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

它的工作正常

我想在 vba 上使用它:

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

现在如何在查询中设置 VAR: CountryCity 类似于 range("A1").value 或将变量 dim city 声明为字符串。

【问题讨论】:

标签: mysql sql excel vba xquery-sql


【解决方案1】:

例如:


Dim country, city

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

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

【讨论】:

  • 所以 var 应该在 '" & var & "' 之间
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-16
  • 1970-01-01
  • 2013-07-13
  • 1970-01-01
  • 2015-02-07
相关资源
最近更新 更多