Results 1 to 3 of 3

Thread: Variables and SQL

  1. #1
    Join Date
    Jan 2003

    Variables and SQL

    I'm having a problem when adding a variable to my SQL.

    This worked.
    strSQL = "Select * from Events WHERE UserID="&uID

    This gave me an error.
    strSQL = "Select * from Events WHERE UserID="&uID&"ORDER BY EventTime"

    I tried many variations but came up with bad bad stuff.

    Maybe someone can suggest a good SQL tutorial?

  2. #2
    Join Date
    Nov 2002
    I presume you are using VB/VBScript to perform the DB call?

    On the first glance i notice a space missing before the order by clause:

    strSQL = "Select * from Events WHERE UserID="&uID&" ORDER BY EventTime"

    What data type is the field UserID? If it is a char or varchar then you should enclose the variable in single quotes:

    strSQL = "Select * from Events WHERE UserID='" & uID & "' ORDER BY EventTime"

    If this does not help, please post the detailed error message you are getting. I am assuming you are getting an OLE DB / ODBC error.

  3. #3
    Join Date
    Feb 2003
    andi_g69 is correct about the spaces, but I wanted to add in that you will also get an error if uid is null.

    When in doubt in situations like this, have your program or ASP page output the query for you and see if it looks right. Try copying the resulting query into Query Analyzer or whatever db you're using and execute it there. You may get a better error that way.

Posting Permissions

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