/*
 EMDT-599 audit log migration
 add new columns to avoid reference to Users table,
 one-off population of new columns.
 Moulya
 21 May 2019
 MSSQL version
 */



UPDATE AUDIT_LOG
SET audit_user_username = u.user_username
from users u
inner join AUDIT_LOG a ON a.audit_user_id = u.user_id

UPDATE AUDIT_LOG
SET audit_user_fullname =
        ltrim(rtrim(concat(ltrim(rtrim(concat(ltrim(rtrim(concat(ltrim(rtrim(concat(u.user_prefix,' ',u.user_forename))),' ',u.user_middlename))),' ',u.user_surname))),' ',u.user_suffix)))
from users u
         INNER JOIN AUDIT_LOG a ON a.audit_user_id = u.user_id
