We currently have a change log that logs any change within our tables on our windows database. The two most important columns in that table are the OldValue and the NewValue columns. When a user changes a TalentCategoryID from one TalentCategoryID to another it shows the change of the ID #. Rather than display the TalentCategoryID I would like to be able to see the Name associated with the TalentCategoryID which I have the name/id relationship in a separate table called TalentCategories.
The problem I am having is that I cannot simply do a JOIN because the TalentCategoryID is in the OldValue and NewValue columns and they are not strictly TalentCategoryID because it is a changelog for multiple tables, columns, and values.
Is there a way to display the OldValue and NewValue as the Name of the TalentCategoryID rather than the ID itself?
Here is the query I have so far:
SELECT T.FirstName, T.LastName, A.TableName, A.ColumnName, A.OldValue, A.NewValue, TC.Name, A.UpdateDate
FROM [AuditLog] A
JOIN Talents T ON A.ModifiedPrimaryKey = T.TalentID
JOIN TalentCategories TC ON TC.TalentCategoryID = T.TalentCategoryID
WHERE TableName = 'Talents'
AND ColumnName = 'TalentCategoryID'
UPDATE 1/31/19 Below
This is the results when I pull the following table AuditLog with the query
SELECT TOP 1000 * FROM dbo.AuditLog
WHERE ColumnName = 'TalentCategoryID'
I am attempting to change the OldValue/NewValue columns from ID numbers to the actual Name value given in another table called TalentCategories this table has an ID column and a Name column. The goal is to be able to easily identify when a TalentCategory is changed from one Category NAME to another category NAME not just seeing a change in ID numbers that I don't know what they mean without looking at the TalentCategories table. Below is an example of what I am trying to achieve...