if:sql查询附近的语法错误

时间:2014-02-27 10:53:03

标签: mysql ios sql if-statement

我在sql if查询中使用了select条件。当我使用if条件时,我收到语法错误

     select a.QM_ID,a.QM_QCM_ID,a.QM_Question,a.QM_Type,a.QM_Parent_Id,c.AM_Answer, c.AM_Comments 
from question_master a INNER JOIN Assessment_master c 
on (c.AM_QM_ID = a.QM_ID AND c.AM_HNM_ID = '%d' AND AND c.AM_HM_ID = '%d' and c.AM_ASM_Local_Id = '%@') where a.QM_Parent_Id = '0' and a.QM_Status = 'A' and a.QM_QCM_ID = '%@' and a.QM_QRM_Id = '%@' 
case when(AM_Comments is  null) THEN 
union 
select b.QM_ID,b.QM_QCM_ID,b.QM_Question,b.QM_Type,b.QM_Parent_Id,null,null 
from question_master b INNER JOIN Assessment_master d 
on ((d.AM_QM_ID = b.QM_Parent_Id OR d.AM_QM_ID = b.QM_ID) AND d.AM_HNM_ID = '%d' AND d.AM_HM_ID = '%d' and d.AM_ASM_Local_Id = '%@') where b.QM_Parent_Id != '0' and b.QM_Status = 'A' and b.QM_QCM_ID = '%@' and b.QM_QRM_Id = '%@'

2 个答案:

答案 0 :(得分:0)

您在if语句中使用select在sqLite中没有if的{​​{1}}命令。 您可以使用select statement代替If。

EXP:Case

答案 1 :(得分:0)

select a.QM_ID,a.QM_QCM_ID,a.QM_Question,a.QM_Type,a.QM_Parent_Id,c.AM_Answer, c.AM_Comments 
from question_master a 
     INNER JOIN Assessment_master c 
         on (c.AM_QM_ID = a.QM_ID 
         AND c.AM_HNM_ID LIKE '%d' AND c.AM_HM_ID LIKE '%d' 
         and c.AM_ASM_Local_Id LIKE '%@') 
     where a.QM_Parent_Id = '0'
         and a.QM_Status = 'A' 
         and a.QM_QCM_ID LIKE '%@' 
         and a.QM_QRM_Id LIKE '%@' AND
         AM_Comments is  null 
union 
    select b.QM_ID,b.QM_QCM_ID,b.QM_Question,b.QM_Type,b.QM_Parent_Id,null,null 
    from question_master b 
    INNER JOIN Assessment_master d 
    on ((d.AM_QM_ID = b.QM_Parent_Id OR d.AM_QM_ID = b.QM_ID) 
       AND d.AM_HNM_ID LIKE '%d' 
       AND d.AM_HM_ID LIKE '%d' 
       and d.AM_ASM_Local_Id LIKE '%@') 
     where b.QM_Parent_Id != '0' 
       and b.QM_Status = 'A' 
       and b.QM_QCM_ID LIKE '%@' 
       and b.QM_QRM_Id LIKE '%@'