UPDATE REF_SQLFIELDS
SET Code = 'CASE ISNULL(CAST(Preferred_Name AS varchar(100)), '') WHEN '' THEN CAST(Forename AS varchar(100)) ELSE CAST(Preferred_Name AS varchar(100)) END'
WHERE Table_Name = 'DT_PERSON'
AND Field_Name = 'calcPreferredName'
AND CustomisationID = 0