I have a table in Excel which I want to use to get some measures via SQL.
This is the first part of my code, which works fine:
Option Explicit
Sub MySQL()
Dim cn As Object, rs As Object, output As String, sql As String
Set cn = CreateObject("ADODB.Connection")
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & ";" & _
"Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
.Open
End With
Now I can get the amount of entries with a specific condition like:
sql = "SELECT COUNT(ID) FROM [Data$] WHERE [Type] = ""myType"" and [Status] = ""myStatus"""
Set rs = cn.Execute(sql)
MsgBox (rs(0))
Now I would like to use a CONTAINS condition, but this does not work:
sql = "SELECT COUNT(ID) FROM [Data$] WHERE CONTAINS([Type], ""T"")"
Set rs = cn.Execute(sql)
MsgBox (rs(0))
%T%