Como solucionar el problema de syntax en SQL Management Studio

Kinyo Yauyo Landeo 0 Reputation points
2024-04-19T23:45:44.0866667+00:00

Tengo el siguiente query cuando corro la consulta genera un error:

Msg 103010, Level 16, State 1, Line 17

Parse error at line: 2, column: 21: Incorrect syntax near 'TABLE'.

Completion time: 2024-04-19T18:40:17.5477601-05:00

-- Declaramos una variable de tipo tabla para almacenar los resultados

DECLARE @Resultados TABLE (

fecha_creacion_date DATE,

centro_carga_cd VARCHAR(255),

centro_carga_desc VARCHAR(255),

fecha_arribo_terminal DATE,

hora_arribo_terminal TIME,

fecha_salida_terminal DATE,

hora_salida_terminal TIME,

tiempo_permanencia_terminal INT,

vehiculo_cd VARCHAR(255),

turno_numb INT,

orden_numb INT,

orden_cd VARCHAR(255),

estacion_cd VARCHAR(255),

estacion_name VARCHAR(255),

fecha_arribo_destino DATE,

hora_arribo_destino TIME,

fecha_salida_destino DATE,

hora_salida_destino TIME,

tiempo_permanencia_destino INT,

cantidad_entregada_qty INT,

producto_cd VARCHAR(255),

transportista_name VARCHAR(255),

placa_val VARCHAR(255),

cisterna_val VARCHAR(255),

estado_desc VARCHAR(255),

OTIF VARCHAR(255)

);

-- Insertamos los resultados de la consulta en la variable @Resultados

INSERT INTO @Resultados (

fecha_creacion_date,

centro_carga_cd,

centro_carga_desc,

fecha_arribo_terminal,

hora_arribo_terminal,

fecha_salida_terminal,

hora_salida_terminal,

tiempo_permanencia_terminal,

vehiculo_cd,

turno_numb,

orden_numb,

orden_cd,

estacion_cd,

estacion_name,

fecha_arribo_destino,

hora_arribo_destino,

fecha_salida_destino,

hora_salida_destino,

tiempo_permanencia_destino,

cantidad_entregada_qty,

producto_cd,

transportista_name,

placa_val,

cisterna_val,

estado_desc,

OTIF

)

SELECT

fecha_creacion_date,

centro_carga_cd,

centro_carga_desc,

fecha_arribo_terminal,

hora_arribo_terminal,

fecha_salida_terminal,

hora_salida_terminal,

tiempo_permanencia_terminal,

vehiculo_cd,

turno_numb,

orden_numb,

orden_cd,

estacion_cd,

estacion_name,

fecha_arribo_destino,

hora_arribo_destino,

fecha_salida_destino,

hora_salida_destino,

tiempo_permanencia_destino,

cantidad_entregada_qty,

producto_cd,

transportista_name,

placa_val,

cisterna_val,

estado_desc,

OTIF

FROM (

SELECT 

    *,

    ROW_NUMBER() OVER (PARTITION BY orden_cd ORDER BY (SELECT NULL)) AS RowNum

FROM [bdv].[det_seguimiento_transp_v]

WHERE Estado_desc IN ('Arribo', 'Finalizado')

) AS Filtrado

WHERE RowNum = 1;

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,749 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 101.2K Reputation points MVP
    2024-04-21T18:46:56.4933333+00:00

    El lenguaje de ese forum es inglese. Por preguntas en español, usa ese URL, por favor: https://learn.microsoft.com/es-es/answers/questions/. Non hablo español sufficiente bueno per escribir un respuesta en español, más responde en inglese.

    .........................................

    The language of this forum is English. For questions in Spanish, use https://learn.microsoft.com/es-es/answers/questions/. I don't speak Spanish well enough to write an answer in Spanish, so I respond in English.

    First of all, SQL Server Management Studio is not giving you an error. SSMS is just a tool you use to communicate with your data source, and SSMS relays the error message from the data source.

    The SQL code you have posted is legal syntax in SQL Server on-prem, and also in Azure SQL Database.

    However, the style of the error message, tells me that you are using Azure Synapse Analytics which is a different product. Synapse also supports T-SQL, the same SQL dialect used in on-prem SQL Server. However, Synapse has a completely different background, and far from all syntax supported by SQL Server is supported in Synapse (at the same time Synapse has syntax not available in SQL Server).

    The error message makes it clear that table variables are not supported in Synapse (which makes sense since that Synpase is a multi-node database).

    0 comments No comments