[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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
0
jasfout
Asked:
jasfout
  • 2
  • 2
1 Solution
 
bruintjeCommented:
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
0
 
Brian CroweCommented:
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.
0
 
jasfoutAuthor Commented:
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
0
 
Brian CroweCommented:
you forgot to close the single quotes around strType

strQuery = "SELECT * FROM Tickets WHERE Type = '" + strType + "'"
0
 
jasfoutAuthor Commented:
>you forgot to close the single quotes around strType

Thank you, thats what I needed
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now