Web Listing 1: Visual Basic Code for StringConcat Function Imports System Imports System.Data Imports System.Data.SqlTypes Imports Microsoft.SqlServer.Server Imports System.Text Imports System.IO Imports System.Runtime.InteropServices ' user-defined serialization ' duplicates matter ' don't care about NULLs ' order matters (ignored) ' don't yield NULL if empty set ' maximum size in bytes is 8000 _ Public Structure StringConcat Implements IBinarySerialize Private sb As StringBuilder Public Sub Init() Me.sb = New StringBuilder() End Sub Public Sub Accumulate(ByVal s As SqlString) If s.IsNull Then Return ' skip NULLs Else Me.sb.Append(s.Value) End If End Sub Public Sub Merge(ByVal Group As StringConcat) Me.sb.Append(Group.sb) End Sub Public Function Terminate() As SqlString Return New SqlString(sb.ToString()) End Function Public Sub Read(ByVal r As BinaryReader) _ Implements IBinarySerialize.Read sb = New StringBuilder(r.ReadString()) End Sub Public Sub Write(ByVal w As BinaryWriter) _ Implements IBinarySerialize.Write If Me.sb.Length > 4000 Then ' limit sb to 8000 bytes w.Write(Me.sb.ToString().Substring(0, 4000)) Else w.Write(Me.sb.ToString()) End If End Sub End Structure ' end StringConcat