INSERT working but UPDATE not working in Database Update Tool

Confluence User - 26 Sep, 2017

This SQL Query runs fine for me from within the Databse Update Tool:

INSERT INTO app_fd_x2_ref_sum (c_request_category, c_resource_type, c_request_amount, c_codes, c_monthYear, dateModified, dateCreated)
SELECT c_Category_1, c_resource_type, c_Amt_1, c_Code_1, '#variable.monthYear#', NOW(), NOW()
FROM app_fd_x2_icontacts JOIN app_fd_x2_accounts
ON app_fd_x2_icontacts.c_Church_Agency_1=app_fd_x2_accounts.c_resource_name
WHERE (app_fd_x2_icontacts.c_Amt_1 IS NOT NULL) OR (app_fd_x2_icontacts.c_Code_1 IS NOT NULL)

However this SQL Query run from within the Database Update Tool, where I am trying to set one column equal to another, does not :

UPDATE app_fd_x2_ref_sum t1, app_fd_x2_ref_sum t2
SET t2.client_amt=t1.request_amount
WHERE t2.resource_type='Client';

The log shows the error:

ERROR 26 Sep 2017 11:40:19 org.joget.apps.app.lib.DatabaseUpdateTool - Error executing plugin
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 'UPDATE app_fd_x2_ref_sum t1, app_fd_x2_ref_sum t2
SET t2.love_inc_amt=t1.request' at line 4

I have tried various forms of this Query and it always errors.

What am I missing?

Thanks, Bill

 

process

5


27 Sep, 2017
confluenceUser
confluenceUser

Hi William Vasu

As a guide for you, I attached a sample app containing a process with a "Database Update" tool with working SQL to update table 'lookup' to table 'destination'.

The SQL I used (kinda similar to yours):

update app_fd_destination a, app_fd_lookup b
set a.c_field1 = b.c_field1
where b.id = '1'

On running the app, first add a record in menu 'Lookup Record'. Add the record with the default values. Then click on 'Run Process' menu, and submit the process. On completion of the process, the app will return you to the 'Destination (After SQL Update)' menu displaying the column Field1 updated with the words 'Hello World' from the first table (Lookup table).

Reminder: All Joget Workflow database table columns starts with 'c_' (except id and dateCreated, dateModified.

APP_29032644.jwa

 

27 Sep, 2017
confluenceUser
confluenceUser

Hi Andrew,

I my particular case what I am trying to do is UPDATE the value of a field/column value in a table with the value of another field/column in the same table by using a table alias. See my example.

This is what seems to error.

Thanks

28 Sep, 2017
confluenceUser
confluenceUser

Hi Andrew,

I got it. The issue was multiple UPDATE statements in one query. What worked was:

UPDATE app_fd_x2_ref_sum
SET c_client_amt = (CASE WHEN c_resource_type = 'Client' THEN c_request_amount
ELSE '0.00'
END),
c_love_inc_amt = (CASE WHEN c_resource_type = 'Love INC' THEN c_request_amount
ELSE '0.00'
END),
c_business_amt = (CASE WHEN c_resource_type = 'Business' THEN c_request_amount
ELSE '0.00'
END),
c_church_amt = (CASE WHEN c_resource_type = 'Church' THEN c_request_amount
ELSE '0.00'
end),
c_agency_amt = (CASE WHEN c_resource_type = 'Agency' THEN c_request_amount
ELSE '0.00'
END)
WHERE c_request_amount IS NOT NULL

Thanks, Bill

30 Sep, 2017
confluenceUser
confluenceUser

In the plugin, it will simply execute the SQL you wrote, so the error is very much between your SQL query and the SQL server that you are pointing to. You should check for MySQL error and solve it by rewriting your query.

30 Sep, 2017
confluenceUser
confluenceUser

One more thing to try. If you run the exact query that you have written directly in the SQL's client/console, you should be getting the same error too. Cheers

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print