SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

Thelma
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

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
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:
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

India
52309 Posts

Posted - 09/21/2012 :  12:57:51  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000