on 2016 Jul 15 5:26 PM
Puedes postear el scritpt porfa.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Buenos dias CAB CANUL JULIAN;
Agradezco tu ayuda, te detallo el query:
DECLARE @Desde DATE, @Hasta DATE
SET @Desde = '20060101'
SET @Hasta = '20160131'
;WITH INV AS
(
SELECT DocEntry, DocNum, CardCode, CardName, DocTotal, S.SeriesName AS Operacion, C.PymntGroup AS CondicionPago, DocDate, DocDueDate, I.GroupNum, ABS(I.DocTotal - I.Paidtodate) AS "Saldo"
FROM
OINV AS I
INNER JOIN NNM1 S On S.Series = I.Series
INNER JOIN OCTG C ON C.GroupNum = I.GroupNum
WHERE
ABS(I.DocTotal - I.Paidtodate)BETWEEN 0 AND 0.99
AND I.DocDate >= @Desde
AND I.DocDate < DATEADD(DD, 1, @Hasta)
AND I.GroupNum NOT IN(19, 43, 47)
AND I.DocSubType = '--'
AND I.Canceled = 'N'
)
SELECT I.CardCode, I.CardName, I.Operacion, I.DocNum, I.CondicionPago, I.DocTotal, I.DocDate, I.DocDueDate, MAX(PH.DocDate) AS UltimoPago, DATEDIFF(DD, I.DocDueDate, MAX(PH.DocDate)) AS DiasAtraso
FROM
RCT2 AS PD
INNER JOIN INV I ON I.DocEntry = PD.DocEntry
INNER JOIN ORCT PH ON PH.DocEntry = PD.DocNum
WHERE
PH.Canceled = 'N'
GROUP BY I.CardCode, I.CardName, I.Operacion, I.DocNum, I.CondicionPago, I.DocTotal, I.DocDate, I.DocDueDate, PD.DocEntry, Saldo
****INTENTALO ASI***
declare @Desde datetime
declare @Hasta datetime
declare @tempo int
SET @tempo=(SELECT * FROM OINV T0 WHERE T0.[DocDate] >=[%0] AND T0.[DocDate] <=[%1])
SET @Desde=(SELECT '[%0]')
SET @Hasta=(SELECT '[%1]')
;WITH INV AS
(
SELECT DocEntry, DocNum, CardCode, CardName, DocTotal, S.SeriesName AS Operacion, C.PymntGroup AS CondicionPago, DocDate, DocDueDate, I.GroupNum, ABS(I.DocTotal - I.Paidtodate) AS "Saldo"
FROM
OINV AS I
INNER JOIN NNM1 S On S.Series = I.Series
INNER JOIN OCTG C ON C.GroupNum = I.GroupNum
WHERE
ABS(I.DocTotal - I.Paidtodate)BETWEEN 0 AND 0.99
AND I.DocDate >= @Desde
AND I.DocDate < DATEADD(DD, 1, @Hasta)
AND I.GroupNum NOT IN(19, 43, 47)
AND I.DocSubType = '--'
AND I.Canceled = 'N'
)
SELECT I.CardCode, I.CardName, I.Operacion, I.DocNum, I.CondicionPago, I.DocTotal, I.DocDate, I.DocDueDate, MAX(PH.DocDate) AS UltimoPago, DATEDIFF(DD, I.DocDueDate, MAX(PH.DocDate)) AS DiasAtraso
FROM
RCT2 AS PD
INNER JOIN INV I ON I.DocEntry = PD.DocEntry
INNER JOIN ORCT PH ON PH.DocEntry = PD.DocNum
WHERE
PH.Canceled = 'N'
GROUP BY I.CardCode, I.CardName, I.Operacion, I.DocNum, I.CondicionPago, I.DocTotal, I.DocDate, I.DocDueDate, PD.DocEntry, Saldo
User | Count |
---|---|
111 | |
8 | |
8 | |
6 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.