On Wed, 25 Jan 2012 11:21:42 -0300, "Sergio H. Gonzalez"
<shg_siste...@yahoo.com.ar> wrote:
> Hello! This may be a silly question, but just in case I ask it anyway...
> 
> Is there any problem in doing something like this?
> 
> select
>      d.descripcion,
>      d.cantidad,
>      p.id as id_plan_ctas,
>      p.descripcion as desc_plan_ctas
> 
> from fac_ven_detalle d
>      left join cont_plan p on ((d.plan_ctas = p.codigo) and 
> (p.id_cont_periodo = :id_periodo))
> 
> where
>      (f.fecha between :desde and :hasta)
> 
> 
> I mean, I'm using the ":id_periodo" param inside the join part of the 
> query. Of course, it works ok, but I just wander if this is the best way

> to do it... or should I move it to the "where" part, like this?
> 
> select
>      d.descripcion,
>      d.cantidad,
>      p.id as id_plan_ctas,
>      p.descripcion as desc_plan_ctas
> 
> from fac_ven_detalle d
>      left join cont_plan p on (d.plan_ctas = p.codigo)
> 
> where
>      (f.fecha between :desde and :hasta)
>      and
>      (p.id_cont_periodo = :id_periodo)
> 
> thanks!!!!!!

It is no problem to use parameters in the JOIN condition. These two
queries however do *not* produce the same result. In the original query if
the condition 'p.id_cont_periodo = :id_periodo' is not satisfied, you will
get a row with values from fac_ven_detalle d with NULL for the columns
defined in cont_plan p as you are using a left join, in the second query
you will *not* get a row.

You don't need to put parentheses around individual conditions (I think it
hurts readability, but that is just a matter of taste).

Mark

Reply via email to