¿Qué hay de malo en esta consulta de SQL Server?

RanchiRhino

¿Qué hay de malo en la siguiente consulta de actualización? da error de sintaxis, el mensaje de error es el siguiente:

Msg 102, nivel 15, estado 1, línea 1
Sintaxis incorrecta cerca de 'a'.

Código:

UPDATE D_date a 
SET d_date_key = b.d_date_key,  
    full_date = b.full_date,    
    day_of_week = b.day_of_week,    
    day_of_week_display = b.day_of_week_display,    
    fiscal_day_number = b.fiscal_day_number 
FROM   
    dbo.[2017 Calendar update] b
WHERE  
    a.d_date_key = b.d_date_key;
Gordon Linoff

Claramente, los alias no están permitidos en la updateparte de la updatedeclaración en SQL Server. En su lugar, use el nombre de la tabla:

UPDATE D_date 
    SET d_date_key = b.d_date_key ,  
        full_date = b.full_date,  
        day_of_week = b.day_of_week,  
        day_of_week_display = b.day_of_week_display,  
        fiscal_day_number = b.fiscal_day_number   
    FROM  dbo.[2017 Calendar update] b
    WHERE D_date.d_date_key = b.d_date_key;

O use un JOINalias explícito y razonable:

UPDATE D_date 
    SET d_date_key = cu.d_date_key ,  
        full_date = cu.full_date,  
        day_of_week = cu.day_of_week,  
        day_of_week_display = cu.day_of_week_display,  
        fiscal_day_number = cu.fiscal_day_number   
    FROM D_date d JOIN
         dbo.[2017 Calendar update] cu
         ON d.d_date_key = cu.d_date_key;

Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.

En caso de infracción, por favor [email protected] Eliminar

Editado en
0

Déjame decir algunas palabras

0Comentarios
Iniciar sesiónRevisión de participación posterior

Artículos relacionados

TOP Lista

CalienteEtiquetas

Archivo