Reputation: 107
I'm using MySQL and EXCEL(VBA) How can I pass an sql query value into a variable?
I have a variable Dim-ed:
Dim sqlVar As Variant
It's variant because I'm not sure which type I should use. I have set the sql query to the variable like this:
sqlVar = "SELECT datum FROM arfolyam ORDER BY datum ASC LIMIT 1 "
But like this, it stores the sql query, not the value of the query!
Any ideas?
Upvotes: 0
Views: 5915
Reputation: 107
...
Dim strSQL as String
...
strSQL = "SELECT column FROM table ORDER BY column DESC LIMIT 1"
Set rs = cn.Execute(strSQL)
variable1 = rs.Fields(0).Value
This way the sql query's value which is in this case is one cell, will be given to the variable1
Upvotes: 1