• Thanks for a good question, I know about STUFF for replacing parts of strings but thought the '0' for the length parameter formed part of a trick question (i.e. insert no characters from @stuffing rather than delete no characters from @string1) so selected 16, not 46.

    Then after getting it wrong 🙁 and researching the question I found this comment from Zafar Yousafi in BOL:

    At first sight it might not be clear directly how to insert a character (or a string) instead of substituting characters in the original string.

    To insert a string, without replacing/substituting characters in the original string you need to specify a length of 0 (zero).

    SELECT STUFF('abcghi', 4, 0, 'DEF');

    -- this results in 'abcDEFghi'.

    So, learned something new today - thanks!

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.