Pulling @variables from a SQL query/sproc into vb/vba vairable
Been struggling with this for a few hours now.
I have a SQL query which gives three vairables (however I can get it to push these vairables out in a 'Select @StatusOn, @StatusOff, @StatusTest' at the end. (this is stored as strSQL)
My code is as follows then I will go through what I have tried
*******************************************************
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim prm As New ADODB.Parameter
With cnn
.Open "DRIVER={SQL Server};SERVER=MYSERVER;DATABASE=MYDB;"
End With
With cmd
.ActiveConnection = cnn
.CommandTimeout = 0
.CommandType = adCmdText
.CommandText = strSQL
End With
cmd.Execute
Set prm = cmd.CreateParameter("StatusOn", adDate, adParamOutput, , **@SatausOn**)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("StatusOff", adDate, adParamOutput, , **@StatusOff**)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("StatusTest", adDate, adParamOutput, , **@StatusTest**)
cmd.Parameters.Append prm
Set cnn = Nothing
*******************************************************
I have pushed the SQL and got it to dump it out then ran it manually and the SQL is bringing back values
I have tested the the parameters are being created and appended to the cmd howver I cant get the prm to be filled with the output value of the query. :confused:
I dont know what to put in **@StatusOn**
I could get the query to return a single record at a time, however this sits within a loop and dont want to hit the DB 3 times per loop
The query can either put out records as variables or in a single row with 3 fields.
I am at a loss with this, I know it has to be possible
Any help would be fantastic