I am trying to calculate a trigger to assign the value of a field with an additional key with automatic addition of "ID", which is automatically created when inserted into another field "Sort_Placement", so after the insert they match.
If you're wondering why I do this, "Sort_Placement" is used as the sort value in the table, which can be changed, but by default the record is added at the bottom of the table
Table data
`ID` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Account_Num` mediumint(8) unsigned NOT NULL, `Product_Num` mediumint(8) unsigned NOT NULL, `Sort_Placement` mediumint(8) unsigned DEFAULT NULL, `Order_Qty_C` smallint(6) NOT NULL DEFAULT '0', `Order_Qty_B` smallint(6) NOT NULL DEFAULT '0', `Discount` decimal(6,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`)
After trigger trigger
CREATE TRIGGER `order_guide_insert_trigger` AFTER INSERT ON `order_guide` FOR EACH ROW BEGIN IF Sort_Placement IS NULL THEN SET Sort_Placement = NEW.ID; END IF; END;
I tried a bunch of combinations using the "NEW" prefix with no luck. For example, put the prefix NEW before each field name.
Try
INSERT INTO `order_guide` (`Account_Num`, `Product_Num`) VALUES ('5966', '3');
Insert error
ERROR 1054: Unknown column 'Sort_Placement' in 'field list'
LukeS source share