CREATING A USER-DEFINED TYPE Find the average

CREATING A USER-DEFINED TYPE Find the average length and the sum of the widths of all of the tiles SELECT CONVERT(CHAR, dbo.LDimAvg(Length)) as Avg, CONVERT(CHAR, dbo.LDimMax(Length)) as Sum FROM Tiles GO 30.2 in 36 in CREATE ASSEMBLY, as explained in Chapter 2, adds the assembly that contains the user-defined type. CREATE TYPE is used to add a user-defined type to a database. CREATE TYPE is followed by the name that you will use to refer to the user-defined type in SQL Server. In this case, we will refer to the type as LDim. CREATE TYPE also has an EXTERNAL NAME that is used to reference the actual implementation of the user-defined type. The EXTERNALNAME is broken into two parts separated by a period. The first part is the name of the assembly that contains the implementation. LDim is the name of the assembly that was previously loaded into the database using the CREATE ASSEMBLYcommand. The second part of the EXTERNAL NAME is the name of the class, in the assembly, that actually implements the user-defined type. In this case, the class is UDT.LDim, because our LDim implementation is in namespace UDT. Note that the namespace name and the class name are enclosed in square brackets. This is required to distinguish the . that separates the name- space from the class name, from the . that separates the assembly name from the class name. If no namespace was involved, the square brackets would not be required. Note the casing of the namespace and class names. These must match those used in the implementation. For case-sensitive languages like C#, this is not an issue. For case-insensitive languages like VB.NET, the casing must match that used in the definition of the class. So, you can see that LDim acts the same way as any other scalar variable. It can be sorted, compared, and, with the help of LDim-specific aggregation functions, aggregated. Creating a User-Defined Type We will now look at how to create a user-defined type. We will create a type meant to represent a linear dimension. It has two parts: value and units. The value is a double. The units can be one of in for inches, ft for feet, and yd for yard.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Bookmark the permalink.

Comments are closed.