• I have had from time to time the unfortunate experience of coming across too strongly. I have seen where others REALLY tend to bash folks. From what I have read in this thread (thus far), you are in good shape. No doubt, you are receiving quality feedback from folks who share the same kind of passion when it comes to XML and MSSQL server. Whats more, it is rather cool to have a contribution get published on an esteemed site such as this - so congrats.

    Now back to your contribution...refactor by exploring the alternatives that have been presented - especially mine - LOL. Although the string maniputation approach works, it is prone to errors and a tremendous amount of overhead not to mention maintainability.

    for xml path ('application'), ROOT('applications')

    For very simple XML document fragments, it works like a champ; for complex hierarchies, it is your very best friend indeed. An alternative, as it pertains to "shaping" XML output, requires many nulls and a bunch of unions and lends itself to yet another maintenance headache. The approach that I have described works in SQL 2005 and up.

    Good luck.

    -M