-1

Why do I get an error saying that the SQL command is not properly ended when I have this code:

SELECT MATERIALID, 
       MATERIALNAME, 
       MATERIALTYPEID, 
       CURECODEID, 
       COMBINATIONCODE, 
       MATERIALSTATUSID, 
       ACTIVATED, 
       DEACTIVATED 
FROM   MATERIAL_HEADER 
WHERE  MATERIALID = 112, 
       MATERIALNAME = 3, 
       MATERIALTYPEID = 2, 
       CURECODEID = 0, 
       COMBINATIONCODE = 3, 
       MATERIALSTATUSID = 3;

I've tried not including the semicolon, parenthesis and some other stuff but none has worked.

9
  • 3
    Why are your WHERE statement parts comma separated? They should be separated with logical operators, - in your case, I suspect you want AND. E.g. WHERE MATERIALID = 112 AND MATERIALNAME = 3 AND ...
    – Bridge
    Aug 8, 2013 at 13:41
  • You have to use AND at the end, not commas.
    – Mike Cheel
    Aug 8, 2013 at 13:41
  • I didn't realize they werent csv, thank you
    – bbesase
    Aug 8, 2013 at 13:43
  • 1
    Why the downvotes? This may be a 'simple' question but it fits the SO requirements.
    – Jan Doggen
    Aug 8, 2013 at 13:44
  • 1
    @surajsingh I'm not discouraging the asking of questions; I'm encouraging people to try to find their own answers first. Like adults do. Aug 8, 2013 at 14:29

3 Answers 3

8

Try

SELECT MATERIALID, MATERIALNAME, MATERIALTYPEID, CURECODEID, COMBINATIONCODE, MATERIALSTATUSID, ACTIVATED, DEACTIVATED 
FROM MATERIAL_HEADER 
WHERE MATERIALID = 112 AND MATERIALNAME = 3 AND MATERIALTYPEID = 2 AND CURECODEID = 0 AND COMBINATIONCODE = 3 AND MATERIALSTATUSID = 3;

AND instead of ,

3
  • I didnt know they werent csv. Thank you!
    – bbesase
    Aug 8, 2013 at 13:43
  • not a problem! One neat thing about SQL is it's designed to read kind of like English: "Select these columns, separated by commas like in English, from this table where this thing and this thing and this thing (are true)" Aug 8, 2013 at 13:47
  • 1
    Oh, and for all of you late to the party, I'd prettied up OP's original query a bit. It was all on one line. Aug 8, 2013 at 13:48
0
SELECT MATERIALID, 
       MATERIALNAME, 
       MATERIALTYPEID, 
       CURECODEID, 
       COMBINATIONCODE, 
       MATERIALSTATUSID, 
       ACTIVATED, 
       DEACTIVATED 
FROM   MATERIAL_HEADER 
WHERE  MATERIALID = 112 AND
       MATERIALNAME = 3 AND
       MATERIALTYPEID = 2 AND
       CURECODEID = 0 AND
       COMBINATIONCODE = 3 AND
       MATERIALSTATUSID = 3
6
  • You had some additional text in your first answer iteration; would you mind adding an explanation on why you answered as such? Aug 8, 2013 at 13:43
  • @ChrisForrence To be honest it was not clear which DB engine was that. So i made it clear that my answer was for SQL Server. I don't know of all the DB engines out there, and there might be one that accepted commas as boolean operators....Though I highly doubt it. Aug 8, 2013 at 14:22
  • That's definitely fair enough, and I agree that it'd be highly unlikely that a database engine accepts commas for boolean operators. However, I would suggest re-adding your "answer-is-specifically-for-sql-server-but-may-also-apply-to-other-db-servers", if so that your answer is not simply just code. Aug 8, 2013 at 14:29
  • @ChrisForrence Would it really matter, since there is already an accepted answer? Aug 8, 2013 at 14:48
  • As of right now, probably not. And dang, you've had a busy month! Aug 8, 2013 at 16:04
0

Firstly, it's always best to format your queries with readable indentation;

Secondly, I think you are having the issue as your SQL script is incorrect (the where clause needs to be with AND.)

i.e.

SELECT MATERIALID, MATERIALNAME, MATERIALTYPEID, CURECODEID, COMBINATIONCODE,         
MATERIALSTATUSID, ACTIVATED, DEACTIVATED 
FROM MATERIAL_HEADER 
WHERE MATERIALID = 112 AND MATERIALNAME = 3 AND MATERIALTYPEID = 2 AND CURECODEID = 0 AND 
COMBINATIONCODE = 3 AND MATERIALSTATUSID = 3;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.