Skip to Content

consulta de fecha y hora con BETWEEN

buenas tardes tengo la siguiente consulta que me devuelva lo facturado de determinada fecha y hora inicio a determinada fecha y hora fin

SELECT T1.[ItemCode], T1.[Dscription], SUM (T1.[Quantity]) AS 'cantidad' FROM OINV T0
INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN BEAS_APL_WKZ T2 ON T2.ItemCode = T1.ItemCode
WHERE T0.[DocDate] BETWEEN [%0] AND [%1] AND T0.[DocTime] BETWEEN [%2] AND [%3]
GROUP BY T1.[ItemCode], T1.[Dscription]
ORDER BY T1.WhsCode,T2.WKZ_ID

donde estoy solicitando la información de el id del articulo, la descripción y la cantidad sumada. para esto tomo un rango de fecha y de hora.

pero cuando los agrupo no me regresa ninguna información y sin agrupar si me regresa información. pero no agrupada.

también no se si esta bien estructurado ya que lo que requiero es poner la fecha de inicio y hora y la fecha final y hora

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2015 at 10:39 PM

    Hola, puedes explicar la parte de "cuando los agrupo no me regresa ninguna información y sin agrupar si me regresa información. pero no agrupada."

    SQL no te permitiria no agrupar, te enviaria un error de que no estan en una sentencia Goup BY los campos que no estes sumando

    Prueba con una subconsulta

    SELECT * FROM

    (

    SELECT

    T1.[ItemCode], T1.[Dscription], SUM (T1.[Quantity]) AS 'cantidad',T1.WhsCode,T2.WKZ_ID

    FROM OINV T0

    INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]

    INNER JOIN BEAS_APL_WKZ T2 ON T2.ItemCode = T1.ItemCode

    WHERE T0.[DocDate] BETWEEN '20150101' AND '20150101' AND T0.[DocTime] BETWEEN '08:00' AND '09:00'

    )X0

    GROUP BY X0.[ItemCode], X0.[Dscription]

    ORDER BY X0.WhsCode,X0.WKZ_ID

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.