jasfout
asked on
How can I compile an sql query statement from multiple variables
For example:
strMyQuerySatement = select * from Tickets where Type = strType and StartDate > strStartDate and EndDate < strEndDate and Paid = blnPaid or Ticket# = strTicketNum
strMyQuerySatement = select * from Tickets where Type = strType and StartDate > strStartDate and EndDate < strEndDate and Paid = blnPaid or Ticket# = strTicketNum
strMyQueryStatement = "SELECT * FROM Tickets WHERE Type = '" + strType + "' AND StartDate > '" + strStartDate + "' AND EndDate < '" + strEndDate + "' AND Paid = " + cint(blnPaid).tostring + " OR Ticket# = '" + strTicketNum + "'"
this will also depend on how you have formated strStartDate and strEndDate. Basically you need to include single quotes around string and date values.
this will also depend on how you have formated strStartDate and strEndDate. Basically you need to include single quotes around string and date values.
ASKER
well to simplify I am for now just trying one variable
here is where I have the trouble
dim strType as string = "ALS"
strQuery = "SELECT * FROM Tickets WHERE Type = '" + strType
...throws an exception
strQuery = "SELECT * FROM Tickets WHERE Type = 'ALS'"
...works fine so I beleive it to be a syntax in this line
here is where I have the trouble
dim strType as string = "ALS"
strQuery = "SELECT * FROM Tickets WHERE Type = '" + strType
...throws an exception
strQuery = "SELECT * FROM Tickets WHERE Type = 'ALS'"
...works fine so I beleive it to be a syntax in this line
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>you forgot to close the single quotes around strType
Thank you, thats what I needed
Thank you, thats what I needed
depends on what you're looking at for variables but something like
--------
Dim strMyQuerySatement As String
strMyQuerySatement = "select * from Tickets where Type = " & strType & " and StartDate > '" & strStartDate & "' and EndDate < '" & strEndDate & "' and Paid = " & blnPaid & " or Ticket# = " & strTicketNum
--------
hope this helps a bit
bruintje