Ver Mensaje Individual
  #4  
Antiguo 14-03-2011
nejamube nejamube is offline
Miembro
 
Registrado: nov 2009
Ubicación: Buenos Aires
Posts: 65
Reputación: 17
nejamube Va por buen camino
Thumbs up Muchas gracias.

Cita:
Empezado por gluglu Ver Mensaje
La base de datos la pude crear con el Script que incluías en tu post de ayer. Eso es lo que te indicaba en mi primer post de hoy.

Lo que no puedo probar correctamente el Select con unos datos que tengan sentido real, porque yo introduje unos datos muy escuetos. Por eso te decía que pude probar el Select indicado, y que a mi no me daba ningún error.
Escribo para agradecerte por tu ayuda, la subconsulta está funcionando perfectamente, es como lo necesitaba. No lo hubiera logrado sin tu ayuda y aprendí algo nuevo.

Este es el código completamente funcional, y no es diferente al que me enviaste en un principio, tu código siempre estuvo correcto, lo que pasa es que tenía mucha presión y no preste atención a tus comentarios.

! Muchas gracias gluglu !

Código SQL [-]
select A.CLAVE, A.NOMBRE, U.NOMBRE UNIDAD, C.NOMBRE CATEGORIA, cast(sum(E.IMPORTE) as float) IMPORTEENTRADA,
       cast(sum(E.CANTIDAD) as integer) CANTIDADENTRADA, cast(sum(S.IMPORTE) as float) IMPORTESALIDA,
       cast(sum(S.CANTIDAD) as integer) CANTIDASALIDA,
       /*SUBCONSULTAS INICIO*/
       (select cast(sum(E2.IMPORTE) as float)
        from ENTRADAS E2
        where E2.ARTICULO = A.CLAVE and
              E2.FECHA between '01-01-2011' and '02-28-2011') as IMPORTEENTRADAANTERIOR,

       (select cast(sum(E2.CANTIDAD) as float)
        from ENTRADAS E2
        where E2.ARTICULO = A.CLAVE and
              E2.FECHA between '01-01-2011' and '02-28-2011') as CANTIDADENTRADAANTERIOR,

       (select cast(sum(S2.CANTIDAD) as float)
        from SALIDAS S2
        where S2.ARTICULO = A.CLAVE and
              S2.FECHA between '01-01-2011' and '02-28-2011') as CANTIDADSALIDAANTERIOR,

       (select cast(sum(S2.IMPORTE) as float)
        from SALIDAS S2
        where S2.ARTICULO = A.CLAVE and
              S2.FECHA between '01-01-2011' and '02-28-2011') as IMPORTESALIDAANTERIOR
       /*SUBCONSULTAS FIN*/
from ARTICULOS A
left join ENTRADAS E on E.ARTICULO = A.CLAVE
left join SALIDAS S on S.ENTRADA = E.CLAVE
left join CATEGORIAS C on A.CATEGORIA = C.CLAVE
left join UNIDADES U on A.UNIDAD = U.CLAVE

where (S.FECHA between :INICIAL and :FINAL) or (E.FECHA between :INICIAL and :FINAL)

group by A.CLAVE, C.NOMBRE, A.NOMBRE, U.NOMBRE
Responder Con Cita