选择字段为空的记录

时间:2012-10-08 08:53:46

标签: android sqlite is-empty

我需要从表中选择一些列,其中某个列(在我的情况下为pos_report_id)为空,而不是null。我在SQLiteDatabaseBrowser中尝试了这个代码(对于user_id ='23'),它运行正常:

"SELECT information_action.target_type, information_action.message_type,"
                + "information_action.start_date, information_action.end_date, information_action.content, information_action.status "
                + "FROM information_action INNER JOIN information_to_user ON "
                + "information_to_user.information_action_id = information_action.id_information_action "
                + "WHERE information_action.pos_report_id ='' AND information_to_user.user_id ='"
                + user_id + "'";

但在代码中,当我运行应用程序时,我收到此错误:

ERROR   AndroidRuntime  Caused by: android.database.sqlite.SQLiteException: near "": syntax error: , while compiling: SELECT information_action.target_type, information_action.message_type,information_action.start_date, information_action.end_date, information_action.content, information_action.status FROM information_action INNER JOIN information_to_user ON information_to_user.information_action_id = information_action.id_information_action WHERE information_action.pos_report_id ='' AND information_to_user.user_id ='23'

知道如何解决这个问题吗?为什么它不适合''?

2 个答案:

答案 0 :(得分:0)

user_id是数据库中的char字段吗?似乎是一个整数。如果这个权利从23中删除'。

答案 1 :(得分:0)

在您的查询中,您同时使用了WHEREON子句。尝试这个只是小改变,而不是WHERE使用AND:

"SELECT information_action.target_type, information_action.message_type,"
                + "information_action.start_date, information_action.end_date, information_action.content, information_action.status "
                + "FROM information_action INNER JOIN information_to_user ON "
                + "information_to_user.information_action_id = information_action.id_information_action "
                + "AND information_action.pos_report_id ='' AND information_to_user.user_id ='"
                + user_id + "'";