Skip to Content
author's profile photo Former Member
Former Member

Query para comisiones.

que tal compañeros, estoy haciendo un query para poder sacar comiisones dependiendo del articulo y fecha de pago.

Es decir que dependiendo cuanto se tardo en pagar la factura el cliente es la comision que se le dara al vendedor, tengo esto:

CASE T3.[DocCur] WHEN 'USD' THEN T3.[DocTotalFC] else T3.[DocTotal] END AS 'Tot Factura',( T3.DocTotal - T3.VatSum) As 'Factura S/IVA', T6.[CommisPcnt] as '% Comision', 
'Com. Normal' = case when ( DATEDIFF(day, T3.docdate, T0.docdate) <=45) then (T4.[LineTotal]*( T6.CommisPcnt/100)) end,
'16-30 Retraso' = case when (DATEDIFF(day, T3.docdate, T0.docdate) >=46 and DATEDIFF(day, T3.docdate, T0.docdate) <=60) then (T4.[LineTotal]*( T6.CommisPcnt/100)*(70/100)) end,
'31-45 Retraso' = case when (DATEDIFF(day, T3.docdate, T0.docdate) >=61 and DATEDIFF(day, T3.docdate, T0.docdate) <=90) then (T4.[LineTotal]*( T6.CommisPcnt/100)*(50/100)) end,
'46-90 Retraso' = case when (DATEDIFF(day, T3.docdate, T0.docdate) >=91 and DATEDIFF(day, T3.docdate, T0.docdate) <=180) then (T4.[LineTotal]*( T6.CommisPcnt/100)*(10/100)) end
FROM ORCT T0  INNER JOIN RCT2 T2 ON T0.DocEntry = T2.DocNum INNER JOIN OINV T3 ON T2.DocEntry = T3.DocEntry INNER JOIN INV1 T4 ON T3.DocEntry = T4.DocEntry INNER JOIN OSLP T5 ON T3.SlpCode = T5.SlpCode INNER JOIN OITM T6 ON T4.ItemCode = T6.ItemCode WHERE T0.[DocDate] >='[%0]' AND  T0.[DocDate] <='[%1]' AND  T5.[SlpName] =[%2] AND T0.[JrnlMemo] <> 'Cancelado'

Los ultimos tres campos que son los que calcula comision checando los dias no me da resultado, solo el campo de "com. Normal" me da......... alguien puede darme un norte de que estoy haciendo mal?

Saludos.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Dec 18, 2008 at 10:14 PM

    Iba a borrar el post pero bueno, lo deja para quien le sirva, el error esta en poner 70/100, 50/100 y asi por el estilo, hay que pone solo 0.7 y 0.5

    Saludos.

    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.