Đang chuẩn bị liên kết để tải về tài liệu:
Microsoft SQL Server 2008 R2 Unleashed- P207

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Microsoft SQL Server 2008 R2 Unleashed- P207:SQL Server 2005 provided a number of significant new features and enhancements over what was available in SQL Server 2000. This is not too surprising considering there was a five-year gap between these major releases.Microsoft SQL Server 2008 is not as much of a quantum leap forward from SQL Server 2005 | 1854 CHAPTER 46 SQLCLR Developing SQL Server Objects in .NET IsNullIfEmpty Tells SQL Server that the UDA will return null if its aggregated value is empty that is if its value is 0 or the empty string and so on . Name Tells the deployment routine what to call the UDA when it is created in the database. MaxByteSize Tells SQL Server not to allow more than the specified number of bytes to be held in an instance of the UDA. You must specify this when using Format.UserDefined. For this example you implement a very simple UDA that sums values in an integer column but only if they are prime. Listing 46.8 shows the code to do this. LISTING 46.8 A UDA That Sums Prime Numbers using System using System.Data using System.Data.Sql using System.Data.SqlTypes using Microsoft.SqlServer.Server Serializable Microsoft.SqlServer.Server.SqlUserDefinedAggregate Format.Native IsInvariantToDuplicates false IsInvariantToNulls true IsInvariantToOrder true IsNullIfEmpty true public struct SumPrime SqlInt64 Sum private bool IsPrime SqlInt64 Number for int i 2 i Number i if Number i 0 return false return true public void Init Sum 0 Developing Custom Managed Database Objects 1855 public void Accumulate SqlInt64 Value if Value.IsNull IsPrime Value Value 1 Sum Value public void Merge SumPrime Prime Sum Prime.Sum public SqlInt64 Terminate return Sum In this code SQL Server first calls Init initializing the private Sum data field to 0. For each column value passed to the aggregate the Accumulate method is called wherein Sum is increased by the value of the column if it is prime. When multiple threads converge Merge is called adding the values stored in each instance as the Prime parameter to Sum. When the rowset has been completely parsed SQL Server calls Terminate wherein the accumulated value Sum is returned. Following are the results of testing SumPrime on Production.Product an existing AdventureWorks2008 table SELECT TOP 10 dbo.SumPrime p.ProductId AS PrimeSum p.Name FROM Production.Product p .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.