问题描述
我正在尝试从JS调用此查询,但是出现语法错误。在这里,我正在检查value是否等于""
或否,但是当我在Js的" "
中编写此查询时,出现错误。我该如何用Js编写不同的文字。
"select * from Slot where Slot.TeacherID="T2" and (Slot.ReservedStudent IS NULL OR Slot.ReservedStudent ="")"
解决方法
内部双引号与外部引号冲突。首先,这是在命中数据库之前在Javascript中出现的语法错误。
您最好在SQL文本中使用单引号-无论如何,这都是文字字符串的标准字符,而双引号代表诸如列或表名之类的标识符(尽管某些数据库(例如MySQL)支持字符串的双引号) :
sql = "select * from Slot where Slot.TeacherID='T2' and (Slot.ReservedStudent IS NULL OR Slot.ReservedStudent = '')"
,
使其类似于以下内容,对值使用单引号
"select * from Slot where Slot.TeacherID='T2' and (Slot.ReservedStudent IS NULL OR Slot.ReservedStudent ='')"