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 ="")"
Advertisement
Answer
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 = '')"