Hello,
I am trying to write a query macro in Excel to query off of an SQL database.
What I cannot seem to figure out is how to have a parameter to return a range of values(like between 2 dates)
MSQuery will not work for me as I will need multiple tables and left outer joins, something MSQuery does not support.
My simplified test query:
[tt]Sub Test()
Dim QT As QueryTable
Dim CS As String
CS = "ODBC;DSN=TMDataMart;UID=sybase;PWD=******;DataBase=TMDataMart"
Set QT = ActiveSheet.QueryTables.Add(CS, Range("A10"), "SELECT Badge, First_name, Last_name, Department FROM Operator WHERE Badge BETWEEN ?[/color red] AND ?[/color red]")
With QT
.RefreshStyle = xlOverwriteCells
.Refresh
End With
End Sub[/tt]
In this case I need to have a parameters for the BETWEEN statement for BADGE. The query works fine the way it is, but gives a prompt for the 2 parameters. I need those parameters to populated from variables.
I apprecaite any assistance anyone can offer
I am trying to write a query macro in Excel to query off of an SQL database.
What I cannot seem to figure out is how to have a parameter to return a range of values(like between 2 dates)
MSQuery will not work for me as I will need multiple tables and left outer joins, something MSQuery does not support.
My simplified test query:
[tt]Sub Test()
Dim QT As QueryTable
Dim CS As String
CS = "ODBC;DSN=TMDataMart;UID=sybase;PWD=******;DataBase=TMDataMart"
Set QT = ActiveSheet.QueryTables.Add(CS, Range("A10"), "SELECT Badge, First_name, Last_name, Department FROM Operator WHERE Badge BETWEEN ?[/color red] AND ?[/color red]")
With QT
.RefreshStyle = xlOverwriteCells
.Refresh
End With
End Sub[/tt]
In this case I need to have a parameters for the BETWEEN statement for BADGE. The query works fine the way it is, but gives a prompt for the 2 parameters. I need those parameters to populated from variables.
I apprecaite any assistance anyone can offer