11-15-2022 09:31 PM
Hi All,
I have written a sql query to update entitlement attributes using CTE(Common Table expression) but I am getting a syntax error in the Saviynt logs which says- "groovy.sql.Sql.withBatch Error during batch execution: 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 'testtable AS". Would you extremely helpful if any sort of alternative method/correction could be suggested.
Query I am using -
WITH testtable AS (select fieldname, fieldkey, minvalue, mxvalue, entitlement_values.ENTITLEMENT_VALUEKEY,ENTITLEMENT_VALUE from fields left join entitlement_objects
ON fields.fieldkey = entitlement_objects.field_key left join entitlement_values ON entitlement_objects.ENTITLEMENT_VALUEKEY = entitlement_values.ENTITLEMENT_VALUEKEY where ENTITLEMENT_VALUE like 'zd%' AND fieldkey=3)
Update entitlement_values set customproperty10 = testtable.minvalue where testtable.ENTITLEMENT_VALUE = entitlement_values.entitlement_value and ENTITLEMENTTYPEKEY=13
Solved! Go to Solution.
11-15-2022 09:51 PM
Query should start with insert/update , use joins
11-17-2022 02:44 AM
Only doubt I have is that how will I update the customproperty of an entitlement with the minvalue (as it is coming from joins for 3 tables) and it does not have any specific name.
11-18-2022 10:40 AM
You can use inner query
11-24-2022 08:33 PM
I tried using the below query and the error I got is -"{"log":"25-Nov-2022 04:27:17.138 WARNING [quartzScheduler_Worker-6] groovy.sql.Sql.withBatch Error during batch execution: You can't specify target table 'entitlement_values' for update in FROM clause\n","stream":"stderr","time":"2022-11-25T04:27:17.138839634Z"}"
update entitlement_values set entitlement_values.customproperty30 = (select minvalue from fields left join entitlement_objects
ON fields.fieldkey = entitlement_objects.field_key left join entitlement_values ON entitlement_objects.ENTITLEMENT_VALUEKEY = entitlement_values.ENTITLEMENT_VALUEKEY where ENTITLEMENT_VALUE like 'zd%' AND fieldkey=3) where entitlement_values.ENTITLEMENTTYPEKEY=13
11-24-2022 08:47 PM
update entitlement_values e set e.customproperty30 = (select minvalue from fields left join entitlement_objects o
ON fields.fieldkey = o.field_key left join entitlement_values v ON o.ENTITLEMENT_VALUEKEY = v.ENTITLEMENT_VALUEKEY where e.ENTITLEMENT_VALUE like 'zd%' AND fieldkey=3) where e.ENTITLEMENTTYPEKEY=13
11-24-2022 08:52 PM
11-24-2022 09:04 PM - edited 11-24-2022 09:04 PM
update fields f left join entitlement_objects o left join entitlement_values e set e.customproperty30 = f.minvalue where f.fieldkey = o.field and o.ENTITLEMENT_VALUEKEY = e.ENTITLEMENT_VALUEKEY and e.ENTITLEMENT_VALUE like 'zd%' AND f.fieldkey=3 and e.ENTITLEMENTTYPEKEY=13
11-24-2022 09:23 PM
groovy.sql.Sql.withBatch Error during batch execution: 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 'set e.customproperty30 = f.minvalue where f.fieldkey = o.field and o.ENTITLEMENT' at line 1\n","stream":"stderr","time":"2022-11-25T05:21:20.749516532Z"}
11-24-2022 09:29 PM
update
fields f,
entitlement_objects o,
entitlement_values e
set
e.customproperty30 = f.minvalue
where
f.fieldkey = o.field
and o.ENTITLEMENT_VALUEKEY = e.ENTITLEMENT_VALUEKEY
and e.ENTITLEMENT_VALUE like 'zd%'
AND f.fieldkey = 3
and e.ENTITLEMENTTYPEKEY = 13
11-24-2022 09:36 PM
11-29-2022 09:38 AM
update
fields f,
entitlement_objects o,
entitlement_values e
set
e.customproperty30 = f.minvalue
where
f.fieldkey = o.field_key
and o.ENTITLEMENT_VALUEKEY = e.ENTITLEMENT_VALUEKEY
and e.ENTITLEMENT_VALUE like 'zd%'
AND f.fieldkey = 3
and e.ENTITLEMENTTYPEKEY = 13
12-06-2022 03:06 AM
{"log":"2022-12-06 11:04:40,303 [quartzScheduler_Worker-1] DEBUG services.SaviyntCommonUtilityService - Error Occured in customQueryExecution - true and exception - java.sql.BatchUpdateException: Unknown column 'f.minvalue' in 'field list'\n","stream":"stdout","time":"2022-12-06T11:04:40.303249252Z"}
12-06-2022 08:02 PM
This is very basis error you should learn SQL
update
fields f,
entitlement_objects o,
entitlement_values e
set
e.customproperty30 = o.minvalue
where
f.fieldkey = o.field_key
and o.ENTITLEMENT_VALUEKEY = e.ENTITLEMENT_VALUEKEY
and e.ENTITLEMENT_VALUE like 'zd%'
AND f.fieldkey = 3
and e.ENTITLEMENTTYPEKEY = 13
12-06-2022 08:38 PM
I did change the column name after I replied you and it worked , thank you so much for the help. Cheers!
12-06-2022 08:46 PM