Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2012

    Unanswered: PLZ HELP - incorrect syntax near (stored string)

    I am writing a code on VB and when the code executes my sql statement brings up an error

    SQL statement:
    "Select ISNULL(FirstName, '') + SPACE(1) + ISNULL(LastName, '') AS FullName, ClassID FROM StudentClassDetails, StudentsInfo where StudentsInfo.StudentID = StudentClassDetails.StudentID And StudentClassDetails.ClassID in '" & SelectedTitles.ToString & "'"

    Error Message:
    Incorrect syntax near '1,6,8,11,14,16,20,21,33,34'.

    '1,6,8,11,14,16,20,21,33,34' is a string stored in SelectedTitles

    Thanks in advance

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    If you display a MessageBox with the SQL statement you're trying to execute, I expect that the problem will jump right out at you.

    You also REALLY need to read up on First Normal Form, it allows you to completely avoid problems like this. See Database normalization - Wikipedia, the free encyclopedia for more information.

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Sep 2006
    Surrey, UK
    Provided Answers: 2
    I suspect that the problem here is that the IN clause requires each element of the list to be delimited. That is, '1','6','8','11','14','16','20','21','33','34'.

    As Pat pointed out, you need to revisit the design of this database with regard to normalisation.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  4. #4
    Join Date
    Jan 2003
    Provided Answers: 11
    you have no parentheses around the list of values you are checking against.

Posting Permissions

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