Using system;using system.data;using system.data.sqlclient;using system.data.sqltypes;using Microsoft.sqlserver.server;using system.text;using System.Collections.Generic; [Serializable] [Microsoft.SqlServer.Server.SqlUserDefinedAggregate (format.userdefined, isinvarianttoduplicates = False, Isinvarianttonulls = True, Isinvarianttoorder = False, Isnullifempty = true, MaxByteSize = 8000)]public struct SU mpart:ibinaryserialize {private StringBuilder _reuslt; Private list<string> _li; public void Init () {//place code here _REUSLT = new StringBuilder (); _li = new list<string> (); } public void accumulate (SqlString Value) {//Place code here if (value.isnull) {return; } else {//_li. ADD (Value.value); if (_reuslt. Length > 0) {_reuslt. Append ("$"); } _reuslt. Append (Value.value); }} public void MErge (Sumpart Group) {//Place code _REUSLT here. Append (GROUP._REUSLT); } public SqlString Terminate () {//Place code//if (LI) here. count>0) Why Li always ==null???? if (_li = = null)//{//return new SqlString (""); } if (_reuslt. Length > 0) {string strreturn = ""; string[] Arraystr = _reuslt. ToString (). Split (' $ '); list<string> li = new list<string> (); for (int i = 0; i < arraystr.length; i++) {li. ADD (Arraystr[i]); } li. Sort (); foreach (string item in Li) {strreturn + = "$" +item; } return new SqlString (Strreturn); return new SqlString (_REUSLT. ToString ()); } return new SqlString (""); }//This is a placeholder member field private int var1; #region ibinaryserialize member public void Read (System.IO.BinaryReader r) { _REUSLT = new StringBuilder (r.readstring ()); public void Write (System.IO.BinaryWriter w) {W.write (_reuslt. ToString ()); } #endregion}
Custom SQL Server Aggregate Culvert count