自訂sql server 彙總涵數

來源:互聯網
上載者:User

標籤:blog   io   ar   os   sp   for   on   div   art   

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 SumPart : IBinarySerialize {    private StringBuilder _reuslt;    //private List<string> _li ;    public void Init()    {        // 在此處放置代碼        _reuslt = new StringBuilder();        //_li = new List<string>();     }    public void Accumulate(SqlString Value)    {        // 在此處放置代碼        if (Value.IsNull)        {            return;        }        else        {            //_li.Add(Value.Value);            if (_reuslt.Length > 0)            {                _reuslt.Append("$");            }            _reuslt.Append(Value.Value);        }    }    public void Merge(SumPart Group)    {        // 在此處放置代碼        _reuslt.Append(Group._reuslt);          }    public SqlString Terminate()    {        // 在此處放置代碼        //if(li.Count>0)  為什麼li老是==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("");    }    // 這是預留位置成員欄位    private int var1;    #region IBinarySerialize 成員    public void Read(System.IO.BinaryReader r)    {        _reuslt = new StringBuilder(r.ReadString());    }    public void Write(System.IO.BinaryWriter w)    {        w.Write(_reuslt.ToString());     }    #endregion}

 

自訂sql server 彙總涵數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.