Split and concatenate function

  • Comments posted to this topic are about the item Split and concatenate function

    Tomaž Kaštrun | twitter: @tomaz_tsql | Github: https://github.com/tomaztk | blog:  https://tomaztsql.wordpress.com/

  • The best splitter for T-SQL is right here[/url] along with several tests. It will outperform any splitter using while loops or xml.

    With it, you can replace your function to this. Note that it has a limit to 4000 unicode chars (8000 for non-unicode) to avoid the use of large data types and improve performance.

    -- Split and concatenate back to string

    CREATE FUNCTION [dbo].[Split_and_concatenate]

    (

    @STR NVARCHAR(4000)

    ,@delimiter CHAR(1)

    )

    RETURNS NVARCHAR(8000)

    AS

    BEGIN

    SELECT STUFF( (SELECT '; ' + CASE Item WHEN '1' THEN '11'

    WHEN '2' THEN '22'

    ELSE '33' END

    FROM dbo.[DelimitedSplitN4K](@str, @delimiter)

    FOR XML PATH('')),1,2, '')

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply