• For the formatting you can try this,

    Use the case to get the correct character in front (or an empty string), and then add the incident_ref in 5 digits. (include leading zero's if needed)

    CASE Event_Type

    WHEN 'c' THEN 'R'

    WHEN 'i' THEN''

    ELSE 'P'

    END + RIGHT('00000' + CAST(incident_ref As nvarchar(5) ), 5)

    Louis