I am doing an audit system and what I have done is a trigger in which the inserted is obtained and saved as JSON in a column, as well as the deleted, but I also want to save the changed fields between inserted and deleted, in postgres I did it using JSON functions, however, for Sql Server I have not yet found a way to do it.
DECLARE @old VARCHAR(MAX) = (SELECT * FROM DELETED FOR JSON AUTO);
DECLARE @new VARCHAR(MAX) = (SELECT * FROM INSERTED FOR JSON AUTO);
--DECLARE @change VARCHAR(MAX) = (@old - @new)
INSERT INTO auditoria (old, new, change) VALUES (@old, @new, @change);
Any suggestions how can I get the @change value?