我正在做一些有意义的简单的事情,
IF EXISTS(SELECT * FROM sysobjects WHERE xtype = 'TF' AND name = 'GetGeographyFromSourceID')
BEGIN
DROP FUNCTION dbo.GetGeographyFromSourceID
END
GO
CREATE FUNCTION dbo.GetGeographyFromSourceID
(
@SourceID INT
)
RETURNS GEOGRAPHY
AS
BEGIN
DECLARE @Longitude FLOAT = 0;
DECLARE @Latitude FLOAT = 0;
DECLARE @Geo GEOGRAPHY;
SELECT @Longitude = Longitude,
@Latitude = Latitude
FROM Sources
WHERE ID = @SourceID;
SELECT @Geo = geography::STGeomFromText('POINT(' + CONVERT(VARCHAR( 100), @Longitude) + ' ' + CONVERT( VARCHAR( 100),@Latitude) + ')', 4326);
RETURN(@Geo)
END
如果存在,则删除它并重新创建它。但我收到错误There is already an object named 'XXX' in the database?