I made a historical table along with a trigger function built in the reference table. Is based on possible name changes for an user and as well recording down the date.
My trigger built:
Target table:
The trigger function pulls the names off the table.
But I'm getting error converting data type. All my data that I'm updating are of VARCHAR type. Where am I missing?



Change the
INSERT..VALUESstatement toINSERT..SELECTand set aliases for all the columns. Make sure the aliases match the every column in the target table (defaulting allNOT NULLcolumns), and they are in the same order as they are declared. Note that theSELECTstatement uses thepatientLastNameChangetable, because theMAX()without aGROUP BYensures only one row is returned. I recommend to useCOALESCEto set theMAX()result to0if it returnsNULL. Then simply add1to increment thelastNameChangeID. I think this is more readable.