• Further on Matt's good advice, I suggest you look into using FOR XML PATH instead of RAW, gives you much better control over the output.
    😎

    If you post the DDL (create table) scripts and some sample data as an insert statement we can take it from there.