Flatten in SQL Server

CREATE TYPE [dbo].[SingleColumnText] AS TABLE (
    [TextValue] NVARCHAR (MAX) NULL);
 
 
create function dbo.Flatten
(
    @input dbo.SingleColumnText readonly
    ,@delimiter nvarchar(max)
)
returns nvarchar(max)
as
begin
    return (
        select stuff((
            select @delimiter + TextValue
            from @input
            for xml path(''), type
        ).value('(./text())[1]', 'nvarchar(max)'), 1, 1, '')
    );
end;

Comments

Popular posts from this blog

C# Record Serialization

Add timestamp to photo using ImageMagick

Read/write large blob to SQL Server from C#