1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Sub test()
Dim TABL As String, cText As String
For i = 2 To 17
If Range("B" & i).Value <> "" Then TABL = TABL & ",'" & Range("B" & i).Value & "'"
Next i
TABL = Mid(TABL, 2)
'1er CAS:
cText = "select h.name,a.tag, h.userid from accountinfo a inner join hardware h on a.hardware_id = h.id where h.NAME in ( 'S2','S42','P15','E41','ER01','41','M98','SE31','SE31','SE59','S02','SR76','S995','SP95','S32');"
'2eme CAS:
'cText = "select h.name,a.tag, h.userid from accountinfo a inner join hardware h on a.hardware_id = h.id where h.NAME in (" & TABL & ");"
MsgBox cText
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DRIVER={MySQL ODBC 5.1 Driver};UID=user;PASSWORD=****;SERVER=host;DATABASE=db1;PORT=3306;", Destination:=Range("$S$14")).QueryTable
.CommandText = Array(cText)
'....suite code
End Sub |
Partager