SQL 关键字“from”附近的语法不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14224040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:02:58  来源:igfitidea点击:

Incorrect syntax near the keyword 'from'

sqlsql-server-2008select

提问by mmilan

I am getting the following error:

我收到以下错误:

Msg 156, Level 15, State 1, Procedure pa_Calcular_Anticipo, Line 31
Incorrect syntax near the keyword 'from'.

消息 156,级别 15,状态 1,过程 pa_Calcular_Anticipo,第 31 行
关键字“from”附近的语法不正确。

I have tried moving blocks of code and commenting, but I can't seem to find the problem.

我试过移动代码块和注释,但我似乎无法找到问题所在。

This is the stored procedure:

这是存储过程:

ALTER procedure [dbo].[pa_Calcular_Anticipo] 
(
    @Tipo_Moneda as numeric(18,0), 
    @Dias as numeric(18,2), 
    @Ciudad_Origen as numeric(18,2), 
    @Ciudad_Destino as numeric(18,2),
    @ArregloPropio int=0
)
 AS
Begin
SET NOCOUNT ON
--Declaracion
Declare @Tasa_Aeropuerto_Origen as numeric(18,2)--
Declare @Tasa_Aeropuerto_Destino as numeric(18,2)--
Declare @Monto_Telefono_Destino as numeric(18,2)--
Declare @Monto_Comida_Destino as numeric(18,2)--
Declare @Monto_Propina_Destino as numeric(18,2)--
Declare @Resultado numeric(18,2)
Declare @Taxi_Aeropuerto_Origen numeric(18,2)--
Declare @Taxi_Aeropuerto_Destino numeric(18,2)--
Declare @Taxi_Interno_Destino numeric(18,2)--

--Obtener Data de la Ciudad Destino
Select  @Tasa_Aeropuerto_Destino = Tasa_Aereoportuaria,
        @Monto_Telefono_Destino = monto_telefono,
        @Monto_Comida_Destino = monto_comida,
        @Monto_Propina_Destino = monto_propina,
        @Taxi_Interno_Destino = Tarifa_Taxi_Interno,
        @Taxi_Aeropuerto_Destino = Tarifa_Taxi_Aeropuerto
from dbo.tb_Ciudades 
where cod_ciudad = @Ciudad_Destino

--Obtener data de la ciudad Origen
Select @Tasa_Aeropuerto_Origen = Tasa_Aereoportuaria,
           @Taxi_Aeropuerto_Origen = monto_telefono,
from dbo.tb_Ciudades 
where cod_ciudad=@Ciudad_Destino

-- Opciones 
IF (@ArregloPropio = 1) --anticipo = si, Traslado = no
              --Monto Calculado = ((Comida + Teléfono + propina) * Días) + (Tasa Aeropuerto Origen + Tasa Aeropuerto Destino)
    BEGIN
        set @resultado = ((@Monto_Comida_Destino + @Monto_Telefono_Destino + @Monto_Propina_Destino) *@Dias) + ( @Tasa_Aeropuerto_Origen +@Tasa_Aeropuerto_Destino)
    END

IF (@ArregloPropio = 2) --Anticipo es igual a “No” y Traslado es igual “No”
    BEGIN
        set @resultado = 0
    END

IF (@ArregloPropio = 3) --Anticipo es igual a “Si” y Traslado es igual “Arreglo Propio”
              --Monto Calculado = ((Comida + Teléfono + propina) * Días) + (Tasa Aeropuerto Origen + Tasa Aeropuerto Destino) + ((Monto Traslados Internos) * Días) + (Traslados Aeropuerto Origen + Traslados Aeropuerto Destino) 
    BEGIN
        set @resultado = ((@Monto_Comida_Destino + @Monto_Telefono_Destino + @Monto_Propina_Destino) *@Dias) + ( @Tasa_Aeropuerto_Origen +@Tasa_Aeropuerto_Destino) + ((@Taxi_Interno_Destino) *Dias) + ( Taxi_Aeropuerto_Destino + @Taxi_Aeropuerto_Origen ) 
    END

IF (@ArregloPropio = 4) --Anticipo es igual a “No” y Traslado es igual “Arreglo Propio”
              --Monto Calculado = (Monto Traslados Internos * Días) + (Tasa Aeropuerto Origen + Tasa Aeropuerto Destino)
    BEGIN
        set @resultado = ((@Taxi_Interno_Destino) *Dias) +( @Tasa_Aeropuerto_Origen +@Tasa_Aeropuerto_Destino)
    END

IF (@ArregloPropio = 5) --Anticipo es igual a “Si” y Traslado es igual “Servicio”
              --Monto Calculado = ((Comida + Teléfono + Propina) * Días) + (Monto Traslados Internos * Días) + (Tasa Aeropuerto Origen + Tasa Aeropuerto Destino)
    BEGIN
        set @resultado = ((@Monto_Comida_Destino + @Monto_Telefono_Destino + @Monto_Propina_Destino) *@Dias) + ((@Taxi_Interno_Destino) *Dias) + ( @Tasa_Aeropuerto_Origen +@Tasa_Aeropuerto_Destino)
    END

IF (@ArregloPropio = 6) --Busqueda por Codigo
    BEGIN
        set @resultado = 0
    END

select @resultado as Monto_Calculado  
end

回答by Sebastian K

You have extra comma, here:

你有额外的逗号,在这里:

Select  @Tasa_Aeropuerto_Origen = Tasa_Aereoportuaria,
        @Taxi_Aeropuerto_Origen = monto_telefono,
from dbo.tb_Ciudades 
where cod_ciudad=@Ciudad_Destino

回答by imreal

Remove the last comma from your second select @Taxi_Aeropuerto_Origen = monto_telefono,

从第二个选择中删除最后一个逗号 @Taxi_Aeropuerto_Origen = monto_telefono,