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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Incorrect Syntax

Author  Topic 

Thelma
Starting Member

1 Post

Posted - 2012-09-21 : 11:43:47
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

BELOW IS THE QUERY EXTRACT.

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
FROM utSchoolYear INNER JOIN
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
Thelma

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-09-21 : 11:58:23
Each condition in the WHERE clause needs a left piece and a right piece. So you need to change it like below:
WHERE  (
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?
WHERE  (
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-21 : 12:57:51
or you need to write them using BETWEEN


...
WHERE (
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
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -