You can also invoke methods that are defined in your UDT in Transact-SQL. The Point class contains three methods, Distance, DistanceFrom, and DistanceFromXY. For the code listings defining these three methods, see Coding User-Defined Types.
The following Transact-SQL statement calls the PointValue.Distance method:
|
SELECT ID, PointValue.X AS [Point.X],
PointValue.Y AS [Point.Y],
PointValue.Distance() AS DistanceFromZero
FROM dbo.Points; |
The results are displayed in the Distance column:
|
IDXYDistance
------------------------
1345
2155.09901951359278
319999.0050503762308 |
The DistanceFrom method takes an argument of Point data type, and displays the distance from the specified point to the PointValue:
|
SELECT ID, PointValue.ToString() AS Pnt,
PointValue.DistanceFrom(CONVERT(Point, '1,99')) AS DistanceFromPoint
FROM dbo.Points; |
The results display the results of the DistanceFrom method for each row in the table:
|
ID PntDistanceFromPoint
---------------------
13,495.0210502993942
21,594
31,990 |
The DistanceFromXY method takes the points individually as arguments:
|
SELECT ID, PointValue.X as X, PointValue.Y as Y,
PointValue.DistanceFromXY(1, 99) AS DistanceFromXY
FROM dbo.Points |
The result set is the same as the DistanceFrom method.