0

I am getting a missing operator error in the following SQL statement:

SELECT Sample.Number, Sample.SampleDate, BOD.BOD_Concentration_IN, BOD.BOD_Concentration_OUT, TSS.TSS_Influent, TSS.TSS_Effluent 
     FROM SampleInformation as Sample 
          INNER JOIN BOD_Data as BOD ON Sample.Number = BOD.Number 
          INNER JOIN TSS_Data as TSS ON Sample.Number = TSS.Number 
     WHERE (DATEPART('m',Sample.SampleDate) = DATEPART('m',#1/13/2016 12:01:00 PM#)) 
     AND (DATEPART('yyyy',Sample.SampleDate) = DATEPART('yyyy',#1/13/2016 12:01:00 PM#)) ORDER BY Sample.SampleDate

I eliminated the "WHERE" clause and still got the error, so it must be in the join.

Can anyone see what I am missing here? Thanks!

2
  • ... and you could use the following: WHERE (MONTH(SampleDate) = MONTH(#1/13/2016 12:01:00 PM#)) AND (YEAR(SampleDate) = YEAR(#1/13/2016 12:01:00 PM#)) Commented Nov 22, 2016 at 20:02
  • @WayneG.Dunn, your comment looks like the right answer. If you put it below (as an answer), then Mr. OReilly can mark this question "answered" and other SO users won't spend time working on this one. Commented Nov 22, 2016 at 22:25

1 Answer 1

0

I finally figured out you are missing ( ) around the 'FROM' clause... try the following:

And BTW, 'Number' does not need to be enclosed in brackets (although it is a reserved word)

SELECT Sample.Number, Sample.SampleDate, BOD.BOD_Concentration_IN, BOD.BOD_Concentration_OUT, TSS.TSS_Influent, TSS.TSS_Effluent 
 FROM (SampleInformation AS Sample 
       INNER JOIN BOD_Data AS BOD ON Sample.Number = BOD.Number) 
       INNER JOIN TSS_Data AS TSS ON Sample.Number = TSS.Number
 WHERE (DATEPART('m',Sample.SampleDate) = DATEPART('m',#1/13/2016 12:01:00 PM#)) 
 AND (DATEPART('yyyy',Sample.SampleDate) = DATEPART('yyyy',#1/13/2016 12:01:00 PM#)) ORDER BY Sample.SampleDate
Sign up to request clarification or add additional context in comments.

3 Comments

Wayne, you were close (see edits in your answer), and your original post got me on the right track. Thanks!
Yes, you did exactly what I did ... used the query builder to create the proper syntax, then add criteria. As for your edit, I rejected it because the only difference you have now is that you enclosed some of the field names in brackets [].... which I also determined didn't cause the issue, so I didn't use them. Glad it's working!!
Okay, fair enough! Thanks for your input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.