Home » Java » MySQL in Java, what is the correct format for an update based on the value in another table [on hold]

MySQL in Java, what is the correct format for an update based on the value in another table [on hold]

Posted by: admin July 12, 2018 Leave a comment

Questions:

I have the following Java code:

    //Update at_cub_awards.ca_award_started to Y if there are task rows with a date
    //otherwise set to N.
    String updateQry = ("UPDATE at_cub_awards dest, " +
                            "(SELECT COUNT(*) noCompletedTasks " +
                            "FROM at_cub_award_date " +
                            "WHERE at_cub_award_date.ca_id = ? AND at_cub_award_date.cad_task_completion_date IS NOT NULL) src" +
                        "SET dest.ca_award_started = if(src.noCompletedTasks > 0,'Y','N') " +
                        "WHERE dest.ca_id = ?;");

When I run it I get the following error:

SQLException in updateYMTask: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dest.ca_award_started = if(src.noCompletedTasks > 0,'Y','N') WHERE dest.ca_id = ' at line 1

This is very similar to the answer at: MySQL – UPDATE query based on SELECT Query

I can not see where the difference is that would cause the error.

Answers: