嗨伙计们:我正在尝试编写一个触发器,该触发器在插入到 SQL Server 2008 中的点表后触发。我第一次尝试似乎正在工作,但无论我如何更改纬度和经度的值随后的插入地理字段保持完全相同
USE GIS
IF EXISTS(SELECT name FROM SYSOBJECTS WHERE name = 'PointCreationTrigger' and type = 'TR')
DROP TRIGGER [dbo].[PointCreationTrigger]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[PointCreationTrigger]
ON [dbo].[Points]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Point AS GEOGRAPHY
DECLARE @Longitude AS FLOAT
DECLARE @Latitude AS FLOAT
DECLARE @WKT AS VARCHAR(256) -- well known text representation of a point
SET @Longitude = (SELECT i.Longitude FROM inserted i)
SET @Latitude = (SELECT i.Latitude FROM inserted i)
IF @Latitude IS NOT NULL AND @Longitude IS NOT NULL
BEGIN
IF @Latitude > -90 AND @Latitude < 90 AND @Longitude > -180 AND @Longitude < 180
BEGIN
SET @WKT = (SELECT 'POINT(' + CONVERT(VARCHAR(16),@Longitude) + ' ' + CONVERT(VARCHAR(16), @Latitude) + ')')
SET @Point = geography::STGeomFromText(@WKT, 4326);
UPDATE [dbo].[Points] SET Point = @Point
END
END
END
GO
有什么建议么...?