0

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?

1 Answer 1

1
...
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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.