Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] UPDATE Query with Auto Actions

9 years 1 month ago - 9 years 1 month ago #270244 by Thelowlandpiper
[SOLVED] UPDATE Query with Auto Actions was created by Thelowlandpiper
Auto Action AfterUserProfileSaved I try to run a query like:
Code:
UPDATE `j25_virtuemart_userinfos` SET `virtuemart_user_id`='[user_id]',`company`=IFNULL('[company]',`company`),`title`=IFNULL('[title]',`title`),`last_name`='[lastname]',`first_name`='[firstname]',`middle_name`=IFNULL('[middlename]',`middle_name`),`phone_1`=IFNULL('[phone]',`phone_1`),`fax`=IFNULL('[fax]',`fax`),`address_1`=IFNULL('[location]',`address_1`),`address_2`=IFNULL('[address]',`address_2`),`city`=IFNULL('[city]',`city`),`virtuemart_state_id`=IFNULL('[state]',`virtuemart_state_id`),`virtuemart_country_id`=IFNULL('[cb_select_country]',`virtuemart_country_id`),`zip`=IFNULL('[zipcode]',`zip`) WHERE `virtuemart_user_id`='[user_id]';

If any of these optional fields are NULL then this merely puts the value [cb_field] into the table, rather than preserving the existing value, which is probably NULL already. Omitting the quotes round the [cb_filed] generates a syntax error/ Is there another way to do this?
Last edit: 9 years 1 month ago by krileon.

Please Log in or Create an account to join the conversation.

9 years 1 month ago - 9 years 1 month ago #270253 by Thelowlandpiper
Replied by Thelowlandpiper on topic SOLVED: UPDATE Query with Auto Actions
The solution seems to be to use a table join with the comprofiler table:
Code:
UPDATE `j25_virtuemart_userinfos` v inner join j25_comprofiler c on v.virtuemart_user_id= c.user_id SET `name`=c.firstname + ' '+ c.lastname,v.company=c.company,`last_name`=c.lastname,`first_name`=c.firstname,`middle_name`=c.middlename,`phone_1`=c.phone,v.`fax`=c.fax,`address_1`=c.location,`address_2`=c.address,v.`city`=c.city,`virtuemart_state_id`=c.state,v.`state`=c.state,`virtuemart_country_id`=c.cb_select_country,`zip`=c.zipcode WHERE `virtuemart_user_id`='[user_id]';
Last edit: 9 years 1 month ago by Thelowlandpiper. Reason: changed topic icon
The following user(s) said Thank You: nant, krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum