avgunitpriceoforderdetails.vb

来自「SQL Server 业已成为最为流行的几大数据库之一」· VB 代码 · 共 47 行

VB
47
字号
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server


<Serializable()> _
<Microsoft.SqlServer.Server.SqlUserDefinedAggregate(Format.Native)> _
Public Structure AvgUnitPriceOfOrderDetails

    Dim Count As Integer
    Dim tempSumPrice As SqlMoney
    Public Sub Init()
        ' 在此处放置代码
        Count = 0
        tempSumPrice = 0
    End Sub

    Public Sub Accumulate(ByVal value As SqlMoney)
        ' 在此处放置代码

        Count = Count + 1
        tempSumPrice = tempSumPrice + value.Value

    End Sub

    Public Sub Merge(ByVal value as AvgUnitPriceOfOrderDetails)
        ' 在此处放置代码
        Accumulate(value.AvgUnitPrice)
    End Sub

    Public Function Terminate() As SqlMoney
        ' 在此处放置代码
        If Count = 0 Then
            AvgUnitPrice = 0
        Else
            AvgUnitPrice = tempSumPrice / Count
        End If
        Return AvgUnitPrice
    End Function

    ' 这是占位符字段成员
    Private AvgUnitPrice As SqlMoney
End Structure

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?