1 using System;
2 using System.Data;
3 using System.Data.SqlClient;
4 using System.Data.SqlTypes;
5 using Microsoft.SqlServer.Server;
6 using System.Collections.Generic;
7 using System.Text;
8
9
10 [Serializable]
11 [SqlUserDefinedAggregate(
12 Format.UserDefined,//use clr serialization to serialize the intermediate result
13 IsInvariantToNulls = true,0)">optimizer property14 IsInvariantToDuplicates = false,128)">15 IsInvariantToOrder = 16 MaxByteSize = 8000) maximum size in bytes of persisted value17 ]
18 public class JoinStr : IBinarySerialize
19 {
20 private StringBuilder _strBuilder;
21 void Init()
22 {
23 _strBuilder = new StringBuilder();
24 }
25
26 void Accumulate(SqlString Value)
27 {
28 if (String.IsNullOrEmpty(Value.Value)) return;
29
30 _strBuilder.Append(Value.Value + "");
31 }
32
33 void Merge(JoinStr Group)
34 {
35 _strBuilder.Append(Group._strBuilder);
36 }
37
38 public SqlString Terminate()
39 {
40 string outPut = "";
41 if (_strBuilder != null && _strBuilder.Length > 0)
42 {
43 outPut = _strBuilder.ToString(0,_strBuilder.Length - 2);
44 }
45
46 return new SqlString(outPut);
47 }
48
49 void Read(System.IO.BinaryReader r)
50 {
51 _strBuilder = new StringBuilder(r.ReadString());
52 }
53
54 void Write(System.IO.BinaryWriter w)
55 {
56 w.Write(_strBuilder.ToString());
57 }
58 }