Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Posts
    2

    Unanswered: query syntax problems

    I am working in vb6 and am new to database access. I can't seem to figure out the syntax for the following:

    rs1.Open "select * from orders where category = '" & button & " and invoice = " & invoice & "' order by guest", db, adOpenStatic, adLockOptimistic

    The above statement doesn't work. What am I doing wrong?

    Jerryb

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: query syntax problems

    Your embedded quotes were misplaced. The SQL being run is like:

    select * from orders where category = 'xxx and invoice = yyy ' order by guest

    But you probably meant this:

    select * from orders where category = 'xxx' and invoice = 'yyy' order by guest

    Try this:

    rs1.Open "select * from orders where category = '" & button & "' and invoice = '" & invoice & "' order by guest", db, adOpenStatic, adLockOptimistic

    (This is assuming that both button and invoice are strings rather than numbers - for numbers, you don't need the quotes.)

    Hint: it's a good idea to print the SQL that is failing to see if it makes sense - e.g.:

    Response.Write "select * from orders where category = '" & button & " and invoice = " & invoice & "' order by guest"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •