创建存储过程以返回lat和long的机场列表

时间:2016-12-16 07:26:39

标签: sql-server stored-procedures

这是我到目前为止所拥有的,但我无法让它正常运行。我一直收到一个错误,语法错误ON FROM它在哪里读FROM TBL_AIRPORT AIR。但是我无法弄清楚那应该是什么,或者要改变什么,所以我无法运行它。任何帮助,将不胜感激。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE SP_GETAIRPORTS
    @GEOLOCATION GEOGRAPHY = NULL,
    @ICAOCODE VARCHAR(10) = NULL,
    @IATACODE VARCHAR(4) = NULL,
    @COUNTRY_FK INT = NULL,
    @STRNAME VARCHAR(MAX) = NULL, 
    @STRCITY VARCHAR(MAX) = NULL,
    @INT_ELEVATION INT = NULL
AS
BEGIN TRANSACTION
BEGIN TRY
    SET NOCOUNT ON
    SET ANSI_WARNINGS OFF

    SELECT 
        GEOLOCATION.LAT, GEOLOCATION.LONG, ICAOCODE, IATACODE, 
        STRNAME, STRCITY, COUNTRY.COUNTRYNAME, INT_ELEVATION 
    FROM 
        TBL_AIPORT AIR
    FROM 
        TBL_AIRPORT AIR
    JOIN 
        TBL_COUNTRY C ON C.COUNTRY_ID = AIR.COUNTRY_FK
    WHERE 
        GEOLOCATION.LAT <> 0 OR GEOLOCATION.LONG <> 0
END TRY
BEGIN CATCH
    -- .....
END CATCH

1 个答案:

答案 0 :(得分:2)

重写您的select子句,因为您使用'TBL_AIRPORT'表两次使用相同的关键字'FROM',并且还正确地编写了开始和提交事务语法。

SELECT 
    GEOLOCATION.LAT, GEOLOCATION.LONG, ICAOCODE, IATACODE, STRNAME,   
    STRCITY, COUNTRY.COUNTRYNAME, INT_ELEVATION 
FROM 
    TBL_AIRPORT AIR
JOIN 
    TBL_COUNTRY C ON C.COUNTRY_ID = AIR.COUNTRY_FK
WHERE 
    GEOLOCATION.LAT <> 0 OR GEOLOCATION.LONG <> 0