Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Incorrect Syntax
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 09/21/2012 :  11:43:47  Show Profile  Reply with Quote
Hi All,

I am new to writing SQL Statements and have written the statement below but get error " Msg 102, Level 15, State 1, Line 14
Incorrect syntax near '='." when I excute the Query


SELECT utSchool.SchoolName, utSchool.LEA, utSchool.DCSFNo, utSchoolGroup.SchoolGroupDescription, utAutosortGroup.Year6Total,
utAutosortGroup.Year6Boys, utAutosortGroup.Year6Girls, utAutosortGroup.TestedTotal, utAutosortGroup.TestedBoys, utAutosortGroup.TestedGirls,
utPupil.HTAppealInd, utPupil.SuccessfulHTAppealInd, utPupil.VRScore, utPupil.NVRScore, utPupil.MathsScore, utAutosortGroup.TotalG,
utAutosortGroup.BoysG, utAutosortGroup.GirlsG
utPupil ON utSchoolYear.SchoolYearId = utPupil.SchoolYearId INNER JOIN
utAcademicYear ON utSchoolYear.AcademicYearId = utAcademicYear.AcademicYearId INNER JOIN
utSchool ON utSchoolYear.SchoolId = utSchool.SchoolId INNER JOIN
utSchoolGroup ON utSchoolYear.SchoolGroupId = utSchoolGroup.SchoolGroupId INNER JOIN
utAretePupilImport ON utPupil.AretePupilKey = utAretePupilImport.AretePupilKey INNER JOIN
utAutosortGroup ON utAcademicYear.AcademicYearId = utAutosortGroup.AcademicYearId

Where (utSchoolGroup.SchoolGroupDescription ='Surrey'
AND (utPupil.VRScore = 75 OR = 80) OR (utPupil.NVRScore < 70 AND <= 80) OR (utPupil.MathsScore <= 60 AND < 70))

Am trying to to meet those conditions in the where clause.

Any Suggestions on how to resolve this issue is gladly welcomed.

Many Thanks

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/21/2012 :  11:58:23  Show Profile  Reply with Quote
Each condition in the WHERE clause needs a left piece and a right piece. So you need to change it like below:
           utSchoolGroup.SchoolGroupDescription = 'Surrey'
           AND (utPupil.VRScore = 75 OR utPupil.VRScore = 80)
           OR (utPupil.NVRScore < 70 AND utPupil.NVRScore <= 80)
           OR (utPupil.MathsScore <= 60 AND utPupil.MathsScore < 70)
But, logically that does not seem to make much sense, so may be this is what you need?
           utSchoolGroup.SchoolGroupDescription = 'Surrey'
           AND (utPupil.VRScore = 75 OR utPupil.VRScore = 80)
           OR (utPupil.NVRScore > 70 AND utPupil.NVRScore <= 80)
           OR (utPupil.MathsScore > 60 AND utPupil.MathsScore < 70)
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 09/21/2012 :  12:57:51  Show Profile  Reply with Quote
or you need to write them using BETWEEN

           utSchoolGroup.SchoolGroupDescription = 'Surrey'
           AND (utPupil.VRScore = 75 OR utPupil.VRScore = 80)
           OR (utPupil.NVRScore BETWEEN 71 AND 80)
           OR (utPupil.MathsScore BETWEEN 61 AND 69)

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000