1

I am trying to call this query from JS but I got syntax error. Here I am checking if value is equal to "" or no but when I write this query inside " " in Js I got an error. How can I write this in Js differently.

"select * from Slot where Slot.TeacherID="T2" and (Slot.ReservedStudent IS NULL OR Slot.ReservedStudent ="")"

2 Answers 2

2

The inner double quotes are clashing with the outer quotes. That's a syntax error in Javascript to begin with, before the database is hit.

You would better use single quotes within the SQL text - that's the standard character for literal strings anyway, while double quotes stand for identifiers such as column or table names (although some databases, such as MySQL, support double quotes for strings):

sql = "select * from Slot where Slot.TeacherID='T2' and (Slot.ReservedStudent IS NULL OR Slot.ReservedStudent = '')"
Sign up to request clarification or add additional context in comments.

Comments

1

Make it something like below ,use single quotes for values

"select * from Slot where Slot.TeacherID='T2' and (Slot.ReservedStudent IS NULL OR Slot.ReservedStudent ='')"

Comments

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.