在应使用条件的上下文(在 'ORDER' 附近)中指定了非布尔类型的表达式。
[code=SQL][/code]SELECT E_Title,E_ID,E_SID,E_Progress ,
(CASE WHEN E_Progress<>1 THEN S_Name END)
FROM Essay,Students WHERE E_TID=1
and (CASE WHEN E_Progress<>1 THEN 'E_SID=S_ID'
END) ORDER by E_ID desc
[color=#FFFFFF][/color]
消息 4145,级别 15,状态 1,第 5 行
在应使用条件的上下文(在 'ORDER' 附近)中指定了非布尔类型的表达式。
我用数据库执行上面代码的时候出现错误。请问是怎么回事啊?
------解决方案--------------------SELECT E_Title,E_ID,E_SID,E_Progress ,
(CASE WHEN E_Progress<>1 THEN S_Name END)
FROM Essay,Students WHERE E_TID=1
and (CASE WHEN E_Progress<>1 THEN 'E_SID=S_ID'
END) ORDER by E_ID desc
貌似错在红色地方的,自己调试一下
------解决方案--------------------SELECT E_Title,E_ID,E_SID,E_Progress ,
(CASE WHEN E_Progress<>1 THEN S_Name END)
FROM Essay,Students WHERE E_TID=1
and (CASE WHEN E_Progress<>1 THEN 'E_SID=S_ID'END) = 'xx'
ORDER by E_ID desc
SELECT E_Title,E_ID,E_SID,E_Progress ,
(CASE WHEN E_Progress<>1 THEN S_Name END)
FROM Essay,Students WHERE E_TID=1
and (CASE WHEN E_Progress<>1 THEN 'E_SID=S_ID'END) <> 'xx'
ORDER by E_ID desc
------解决方案--------------------要用case when也应该是这样
SQL code
and E_SID = (CASE WHEN E_Progress<>1 THEN S_ID else E_SID end)
------解决方案--------------------
SQL code
--这种就应该不报错了
SELECT
E_Title,E_ID,E_SID,E_Progress ,
(CASE WHEN E_Progress<>1 THEN S_Name END)
FROM Essay,Students WHERE E_TID=1
--and (CASE WHEN E_Progress<>1 THEN 'E_SID=S_ID' END) 这个不是一个条件,这是个值
ORDER by E_ID desc
------解决方案--------------------
SQL code
SELECT E_Title,E_ID,E_SID,E_Progress ,(CASE WHEN E_Progress<>1 THEN S_Name END) S_Name
FROM Essay,Students WHERE E_TID=1
and E_SID=S_ID
union
SELECT E_Title,E_ID,E_SID,E_Progress ,null
FROM Essay,Students WHERE E_TID=1
and E_SID<>S_ID
ORDER by E_ID desc