Ver Mensaje Individual
  #7 (permalink)  
Antiguo 28/05/2013, 11:08
Avatar de swatt
swatt
 
Fecha de Ingreso: septiembre-2010
Mensajes: 155
Antigüedad: 13 años, 7 meses
Puntos: 4
Respuesta: Error al usar RIGHT JOIN

Si mira mi consulta original es esta:

Código SQL:
Ver original
  1. SELECT D.Art_id, D.Detalle_Cantidad, D.Detalle_Costo_Unitario , CASE isnull(O.Fecha_Desde,0) WHEN 0 THEN 0 ELSE 3 END Valor
  2.                        FROM   Orden_Loc_Detalle D WITH(NoLock) ,
  3.                               Com_Ofertas O WITH(Nolock)
  4.                        WHERE  D.Emp_id   = 1
  5.                        AND    D.Orden_id = 29279
  6.                        AND    D.Suc_id   = 2
  7.                        AND    D.Detalle_Envio_Prov = 'si'
  8.                        AND    O.Emp_id   =* D.Emp_id
  9.                        AND    O.Suc_id   =* D.Suc_id
  10.                        AND    O.Art_id   =* D.Art_id
  11.                        AND    O.Prov_id  = 316
  12.                        AND    CONVERT(VARCHAR(10),Getdate(),112)     BETWEEN
  13.                            CONVERT(VARCHAR(10),O.Fecha_Desde,112) AND
  14.                            CONVERT(VARCHAR(10),O.Fecha_Hasta,112)
  15.                       ORDER BY Valor

Entonces como pueden ver tengo asi "O.Emp_id =* D.Emp_id", lo que hice fue quitar el =* y poner RIGHT JOIN y quedo asi:

Código SQL:
Ver original
  1. SELECT D.Art_id, D.Detalle_Cantidad, D.Detalle_Costo_Unitario , CASE isnull(O.Fecha_Desde,0) WHEN 0 THEN 0 ELSE 3 END Valor
  2.                        FROM   Com_Ofertas  O WITH(Nolock)
  3.                        RIGHT OUTER JOIN Orden_Loc_Detalle D WITH(NoLock)
  4.                        ON O.Emp_id = D.Emp_id AND O.Suc_id = D.Suc_id AND O.Art_id = D.Art_id
  5.                        WHERE  D.Emp_id   = 1
  6.                        AND    D.Orden_id = 29279
  7.                        AND    D.Suc_id   = 2
  8.                        AND    D.Detalle_Envio_Prov = 'si'
  9.                        AND    O.Prov_id  = 316  
  10.                        AND    CONVERT(VARCHAR(10),Getdate(),112)     BETWEEN
  11.                            CONVERT(VARCHAR(10),O.Fecha_Desde,112) AND
  12.                            CONVERT(VARCHAR(10),O.Fecha_Hasta,112)
  13.                        ORDER BY Valor

Entonces como ven tengo los mismo parametros y todo similar, entonces cuando ejecuto la consulta original si me trae datos pero la que he modificado ya no, hasta he llegado a pensar que la original esta mal y por ende al actualizarla ya no trae nada