on 02-28-2023 3:52 PM
Buenos días.
Tengo el siguiente requerimiento, pero al incluir un filtro más, los criterios de selección salen incorrectos. Debería pedirme dos fechas y un agente de ventas, pero en cambio me pide 3 fechas.
De ante mano gracias a quien me pueda brindar ayuda.
---------------
DECLARE @FINIQ DATE , @FFINQ DATE
SET @FINIQ = /*SELECT TOP 1 T0.DocDate FROM OVPM T0 WHERE T0.DocDate = */ [%0]
SET @FFINQ = /*SELECT TOP 1 T0.DocDate FROM OVPM T0 WHERE T0.DocDate = */ [%1]
Declare @Agente = /*Select top 1 slpname from oslp where slpname =*/ '[%2]'
Select * from(
SELECT
t0.CardCode,
T0.CardName,
'Activo' Status,
t1.SlpName'A.V.',
(Select Docnum from OINV Where Docentry = ((Select max(docentry) from oinv where cardcode=t0.cardcode)))'Factura',
(Select DocDate from OINV Where Docentry = ((Select max(docentry) from oinv where cardcode=t0.cardcode)))'Fecha Última Compra',
(Select DocTotal from OINV Where Docentry = ((Select max(docentry) from oinv where cardcode=t0.cardcode)))'Monto Última Compra',
(Select count(docstatus) from OQUT where DocStatus = 'O' and t0.CardCode = CardCode)'Ofertas Abiertas',
(Select count(docstatus) from OQUT where DocStatus = 'C' and CANCELED = 'N' and t0.CardCode = CardCode)'Ofertas Cerradas',
(Select count(docstatus) from OQUT where DocStatus = 'C' and CANCELED = 'Y' and t0.CardCode = CardCode)'Ofertas Canceladas' FROM
OCRD T0 INNER JOIN OSLP T1 ON T0.SlpCode=t1.SlpCode
left JOIN OQUT T2 ON T0.[CardCode] = T2.[CardCode]
WHERE
cardtype='C' and
ValidFor='Y' and
frozenFor='N'
union select
t0.CardCode,
t0.CardName,
'Inactivo' Status,
t1.SlpName'Vendedor',
(Select Docnum from OINV Where Docentry = ((Select max(docentry) from oinv where cardcode=t0.cardcode)))'Última Compra',
(Select DocDate from OINV Where Docentry = ((Select max(docentry) from oinv where cardcode=t0.cardcode)))'Fecha Última Compra',
(Select DocTotal from OINV Where Docentry = ((Select max(docentry) from oinv where cardcode=t0.cardcode)))'MXP',
(Select count(docstatus) from OQUT where DocStatus = 'O' and t0.CardCode = CardCode)'Ofertas Abiertas',
(Select count(docstatus) from OQUT where DocStatus = 'C' and CANCELED = 'N' and t0.CardCode = CardCode)'Ofertas Cerradas',
(Select count(docstatus) from OQUT where DocStatus = 'C' and CANCELED = 'Y' and t0.CardCode = CardCode)'Ofertas Canceladas' FROM
OCRD T0 INNER JOIN OSLP T1 ON T0.SlpCode=t1.SlpCode
left JOIN OQUT T2 ON T0.[CardCode] = T2.[CardCode]
WHERE
cardtype='C' and
ValidFor='N' and
frozenFor='Y') a where a.[Fecha Última Compra] between @FINIQ and @FFINQ and a.[A.V.] = @Agente
User | Count |
---|---|
107 | |
12 | |
10 | |
5 | |
5 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.