gpt4 book ai didi

mysql - Excel 多列的 SQL IN 语句

转载 作者:行者123 更新时间:2023-11-29 12:12:43 25 4
gpt4 key购买 nike

使用 VBA、Excel 2007 和以下连接字符串:

"provider=Microsoft.ACE.OLEDB.12.0;Data Source=myFile.xlsx; Extended Properties=Excel 12.0"    

我正在尝试执行以下查询SELECT [col1], [col2] FROM [Sheet1$] WHERE ([col1], [col2]) IN ((val1, val2), (val3, val4 ), (val5, val6))

唉,VBA 错误指出它不喜欢查询表达式中的逗号。

我可以执行任何语法更改来运行此查询吗?或者另一个可以做同样事情的查询?

下面是每个请求的周围代码

Sub testQuery()
Dim conStr As String, sql As String
conStr = "provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\me\Desktop\QueryMe.xlsx; Extended Properties=Excel 12.0"
sql = "SELECT col1, col2 FROM [Sheet1$] WHERE (col1, col2) IN (('val1', 'val2'), ('val3', 'val4'), ('val5', 'val6'))"
Dim objCon As Object, objRS As Object
Set objCon = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.RecordSet")

objCon.Open con
objRS.Open sql, con
objRS.Close
objCon.Close
End Sub

最佳答案

你也许可以摆脱这个:

sql = "SELECT col1, col2 FROM [Sheet1$] WHERE col1+col2 IN ('val1val2','val3val4','val5val6')"

关于mysql - Excel 多列的 SQL IN 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30380376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com