Ayuda SAP

Error en script de ventas

Hola a todos, tengo el siguiente script para mostrar las ventas del mes, pero observo que me aparecen unas notas de debito del 2019, es algo raro. ¿Alguien me podria decir que me faltaria para que no carguen esas ND, ya que la consulta es Mayo 2021?

SELECT T0.DocNum NumeroDocumento,
	T0.FolioPref PrefijoFolio,
	T0.FolioNum NumeroFolio,
	CASE WHEN T0.DocSubType = '--' THEN 'FACTURA'
		WHEN T0.DocSubType = 'DN' THEN 'NOTA DE DEBITO'
		END TipoDocumento,
	T0.DocDate FechaCreacion,
	CASE WHEN T1.U_TIPO_ID = 'C' THEN 'CEDULA'
		WHEN T1.U_TIPO_ID = 'R' THEN 'RUC'
		WHEN T1.U_TIPO_ID = 'P' THEN 'PASAPORTE'
		WHEN T1.U_TIPO_ID = 'F' THEN 'CONSUMIDOR FINAL'
	END TipoIdentificacion,
	T1.CardCode Identificacion,
	T1.CardName NombreCliente,
	ISNULL(T1.CardFName, '') NombreComercial,
	T0.SlpCode CodigoSapVendedor,
	ISNULL(T2.U_sabCodMobilVendor, '') CodigoAppVendedor,
	T2.SlpName Vendedor,
	--T10.Name Supervisor,
	UPPER(T3.GroupName) GrupoCliente,
	T4.Name Canal,
	T5.Name MacroCanal,
	T0.Address Direccion,
	T1.City Ciudad,
	T6.Name Zona,
	ISNULL(T1.Phone1, '') Telefono_1,
	ISNULL(T1.Phone2, '') Telefono_2,
	ISNULL(T1.E_Mail, '') Email,
	T7.ItemCode Articulo,
	T7.Dscription Descripcion,
	ISNULL(UPPER(T9.ItmsGrpNam), '') GrupoArticulo,
	--UPPER(T11.Name) CategoriaItems,
	--UPPER(T12.Name) SubCategoriaItems,
	T7.Quantity CantidadFacturada,
	T7.PriceBefDi PrecioPorArticulo,
	T7.DiscPrcnt PorcentajeDescuento,
	T7.Price PrecioTrasDescuento,
	T7.LineTotal TotalLinea,
	T0.DocTotal TotalFactura FROM OINV T0  INNER JOIN OCRD T1 ON T0.[CardCode] = T1.[CardCode] INNER JOIN OSLP T2 ON T0.[SlpCode] = T2.[SlpCode] INNER JOIN OCRG T3 ON T1.[GroupCode] = T3.[GroupCode] INNER JOIN [dbo].[@GRUPO_SN]  T4 ON T1.[U_GrupoSN] = T4.[Code] INNER JOIN [dbo].[@SN_MACROCANAL]  T5 ON T1.[U_MacroCanal] = T5.[Code] INNER JOIN [dbo].[@SN_ZONAS_NUEVAS]  T6 ON T1.[U_Zonas] = T6.[Code] INNER JOIN INV1 T7 ON T0.[DocEntry] = T7.[DocEntry] INNER JOIN OITM T8 ON T7.[ItemCode] = T8.[ItemCode] INNER JOIN OITB T9 ON T8.[ItmsGrpCod] = T9.[ItmsGrpCod] WHERE YEAR(T0.DocDate) = 2021 AND
	MONTH(T0.DocDate) = 5 AND
	T0.CANCELED = 'N' OR
	T0.CANCELED = 'Y' AND
	(T7.AcctCode NOT IN ('_SYS00000000054','_SYS00000000939','_SYS00000000325')) OR    
    T7.AcctCode IN ('_SYS00000000328','_SYS00000000329','_SYS00000000981','_SYS00000000332','_SYS00000000333','_SYS00000000982')

Buenas tardes, esa sentencia OR la deberias utilizar dentro de parentesis ()

1 me gusta