Link to home
Start Free TrialLog in
Avatar of jasfout
jasfoutFlag for United States of America

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
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hello jasfout,

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
Avatar of Brian Crowe
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.
Avatar of jasfout

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
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasfout

ASKER

>you forgot to close the single quotes around strType

Thank you, thats what I needed