在存储过程中调用我的函数时遇到问题。
下面,我创建了一个函数:makePoint
。我想在存储过程中使用它
select * from my_table where dbo.makePoint(lon, lat).STWithin(my polygon)
但是我不能使用该功能。
错误消息:
该功能是找不到用户定义的功能“ makePoint”。
我想念什么?我已经在dbo中创建了SP和功能。
-- ================================================
-- Template generated from Template Explorer using:
-- Create Inline Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER FUNCTION dbo.makePoint(@lon FLOAT, @lat FLOAT)
RETURNS Geometry
AS
BEGIN
DECLARE @g Geometry
SET @g = Geometry::Point(@lon, @lat, 4326)
RETURN @g
END
GO
和我的存储过程
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE OR ALTER PROCEDURE dbo.spGetItemsInRegion @regionId INT
AS
BEGIN
SET NOCOUNT ON
declare @geo as Geometry
select @geo = polygon from something where id = @regionId
select * from my_table where dbo.makePoint(lon, lat).STWithin(@geo)
END
GO