- Identify the name of the customer in the crm_customer table name column
- Use the following SQL Statement to add the taxes to the customer automatically by replacing 'Customer Name' in the WHERE clause with the name from Step 1.
-- Insert data into erp_customer_taxes table
-- Select the id_primary and id_region from crm_customer where the customer's name matches 'Customer Name'
INSERT INTO erp_customer_taxes (id_customer, id_system_tax)
SELECT id_primary, id_region
FROM crm_customer
WHERE name = 'Customer Name';
-- Retrieve the newly created id_primary and join with additional tables to get detailed information
SELECT
ec.id_primary AS 'New Tax id_primary', -- Alias for the new tax id_primary
c.name AS 'Customer Name', -- Alias for the customer's name
c.id_primary AS 'Customer id_primary', -- Alias for the customer's id_primary
sr.province AS 'Province', -- Alias for the province from system_regions
sr.country AS 'Country', -- Alias for the country from system_regions
st.type AS 'Tax Type', -- Alias for the tax type from system_taxes
st.percentage AS 'Percentage' -- Alias for the tax percentage from system_taxes
FROM
erp_customer_taxes ec
JOIN
crm_customer c ON ec.id_customer = c.id_primary -- Join with crm_customer on customer id
JOIN
system_regions sr ON c.id_region = sr.id_primary -- Join with system_regions on region id
JOIN
system_taxes st ON c.id_region = st.id_system_region -- Join with system_taxes on system region id
WHERE
ec.id_primary = LAST_INSERT_ID(); -- Filter to get the last inserted id_primaryThis should display the results to verify taxes were added successfully. (See example below)
