• You can make this function more generic by taking one more parameter

    @Separator VARCHAR(5)

    and inside the code instead of hard-coded comma you could use this parameter.

    This will handle the cases where individual values in @InputString contain commas themselves, where you would want to use a different separator than comma.