Home:ALL Converter>script a dynamic code to insert values into variables and also variables are the column names

script a dynamic code to insert values into variables and also variables are the column names

Ask Time:2019-09-26T11:14:31         Author:harold quek

Json Formatter

How do I write a dynamic script whereby the column name;

GST is a variable and I want it to be dynamically calculated based on the formula whenever there is data insert into the gross_sales column

SET @GST = gross_sales * 0.07, @gross_sales = 'gross_sales';

INSERT INTO sales(invoice_no, GST, gross_sales)
VALUES ('INV-1', @GST, 11.00),
       ('INV-2', @GST, 1.20),
       ('INV-3', @GST, 1.20);

I want the values of the GST column to be calculated automatically whenever data is being inputted into the gross_sales column. I have tried declaring the variables but it didn't work out.

Author:harold quek,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58109080/script-a-dynamic-code-to-insert-values-into-variables-and-also-variables-are-the
yy