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

    Unanswered: incorrect syntax near the keyword 'where'

    Please help!


    I keep getting erroe.. incorrect syntax near the keyword 'where'

    "SELECT ISNULL(LastName, '') + SPACE(1) + ISNULL(FirstName, '') AS FullName,Grade,ClassID FROM studentsInfo,StudentClassDetails Where StudentsInfo.StudentID = StudentClassDetails.StudentID And FullName='" & aName & "' And where ClassID='" & clsID & "' group by fullname"

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    the error message tells you where the SQL parser gave up trying to work out what you were trying to do. so the error occured on or before the 'WHERE'

    in this case I'd expect its your FROM cluase
    that should be a single table
    to use more than one table in a select you need to use the JOIN clause or the deprecated theta join syntax. you used the theta syntax in
    Code:
    Where StudentsInfo.StudentID = StudentClassDetails.StudentID
    [code]FROM studentsInfo JOIN StudentClassDetails Where StudentClassDetails.StudentID = StudentsInfo.StudentID
    WHERE FullName='" & aName & "' And.....

    you only use WHERE once in any SQL statement

    check the details of the syntax for the server version you are using
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    No, the problem is that he has TWO where clauses in a single statement. Proper formatting of your code can reveal these kinds of mistakes:

    Code:
    "
    SELECT	ISNULL(LastName, '') + SPACE(1) + ISNULL(FirstName, '') AS FullName,
    	Grade,
    	ClassID
    FROM	studentsInfo,
    	StudentClassDetails
    Where	StudentsInfo.StudentID = StudentClassDetails.StudentID
    	And FullName='" & aName & "'
    	And where ClassID='" & clsID & "'
    group by fullname
    "
    This should be written like this:
    Code:
    "
    SELECT	ISNULL(LastName, '') + SPACE(1) + ISNULL(FirstName, '') AS FullName,
    	Grade,
    	ClassID
    FROM	studentsInfo
    		inner join StudentClassDetails on StudentsInfo.StudentID = StudentClassDetails.StudentID
    Where	FullName='" & aName & "'
    	And ClassID='" & clsID & "'
    group by fullname
    "
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Oct 2012
    Posts
    5
    Thanks all!

    Got it fine!

Posting Permissions

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