Ver Mensaje Individual
  #10 (permalink)  
Antiguo 29/09/2011, 12:29
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 9 meses
Puntos: 774
Respuesta: Problema con un Select y Where

Te regresa varios registros porque nada mas estas filtrando la primer tabla

id_sta14, Cod_pro_cl, fecha_mov, n_comp, ncomp_in_s, t_Comp, tcomp_in_s
295755, LP0001, 2011-09-29 00:00:00.000, X000500000001, 00000001, REM, RE

WHERE ((sta14.fecha_mov='2011-09-29') and (sta14.T_COMP='FAC' or sta14.T_COMP='REM') and (sta14.tcomp_in_s='FR' or sta14.tcomp_in_s='RE'))

si te fijas ese renglon cumple con la condicion que pones tiene una fecha igual a 2011-09-29, la comp es 'Rem o Fac' y la comp_in_s es 'RE' por lo que al unirlo con la otra tabla te traera todos donde el id sea igual al de esta tabla, porque no pones tambien que te traiga de la segunda tabal nada mas los Re o los FR

WHERE ((sta14.fecha_mov='2011-09-29') and (sta14.T_COMP='FAC' or sta14.T_COMP='REM') and (sta14.tcomp_in_s='FR' or sta14.tcomp_in_s='RE'))
and ((sta20.fecha_mov='2011-09-29') and (sta20.T_COMP='FAC' or sta20.T_COMP='REM') and (sta20.tcomp_in_s='FR' or sta20.tcomp_in_s='RE'))


o ponlo todo en tu join FROM sta14 INNER JOIN sta20 ON sta20.ncomp_in_s = sta14.ncomp_in_s and sta20.fecha=sta14.fecha and.......
Saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me