y si le pones un group by???
Código SQL:
Ver originalSELECT * FROM(
SELECT c.CodigoDeTienda AS CODTIENDA,
c.NombreDeTienda AS TIENDA,
c.CODCP ,
---c.NOMCP AS CP,
C.CodigoDelItem AS CODITEM,
C.NombreDelItem AS ITEM,
(c.InventarioAnteriorANT + c.ComprasANT + c.AjustesANT - c.CreditosANT - c.InventarioActualANT)AS VentasAnterior ,
(c.InventarioAnteriorACT + c.ComprasACT + c.AjustesACT - c.CreditosACT - c.InventarioActualACT)AS VentasActual
FROM (SELECT B.CodTerAtu,
B.CodLoj AS CodigoDeTienda,
B.NomLoj AS NombreDeTienda,
A.CodCp, A.CodIte AS CodigoDelItem,
A.NomIte AS NombreDelItem,
CAST(D.ValPre AS DECIMAL(15, 2)) / 100 AS PrecioANT,
D.ValEstAnt AS InventarioAnteriorANT,
D.ValComDir + D.ValComAta AS ComprasANT,
ISNULL(F.ValSdFab + F.ValCeFab + F.ValNopaFab + F.ValSdAta + F.ValCeAta + F.ValNopaAta + F.ValEopaAta + F.ValCepaAta, 0) AS AjustesANT,
D.ValCre AS CreditosANT, D.ValEstLoj + D.ValEstDep + D.ValEstOut + D.ValEstMB AS InventarioActualANT,
CAST(A.ValPre AS DECIMAL(15, 2)) / 100 AS PrecioACT, A.ValEstAnt AS InventarioAnteriorACT, A.ValComDir + A.ValComAta AS ComprasACT,
ISNULL(C.ValSdFab + C.ValCeFab + C.ValNopaFab + C.ValSdAta + C.ValCeAta + C.ValNopaAta + C.ValEopaAta + C.ValCepaAta, 0) AS AjustesACT,
A.ValCre AS CreditosACT, A.ValEstLoj + A.ValEstDep + A.ValEstOut + A.ValEstMB AS InventarioActualACT
FROM LOT12MJ AS A INNER JOIN
LOJ12MJ AS B ON A.CodLoj = B.CodLoj LEFT OUTER JOIN
AJU12AM AS F ON A.CodCp = F.CodCp AND A.CodLoj = F.CodLoj AND A.CodIte = F.CodIte LEFT OUTER JOIN
AJU12MJ AS C INNER JOIN
LOT12AM AS D INNER JOIN
LOJ12AM AS E ON D.CodLoj = E.CodLoj ON C.CodIte = D.CodIte AND C.CodCp = D.CodCp ON F.CodCp = C.CodCp AND F.CodLoj = D.CodLoj AND
F.CodCp = D.CodCp AND F.CodIte = D.CodIte AND F.CodIte = C.CodIte AND F.CodLoj = C.CodLoj AND A.CodLoj = E.CodLoj AND A.CodCp = D.CodCp AND
A.CodIte = D.CodIte AND B.CodLoj = E.CodLoj AND A.CodLoj = D.CodLoj AND A.CodLoj = C.CodLoj AND A.CodCp = C.CodCp AND
A.CodIte = C.CodIte
WHERE (B.StaAud = 3) AND (E.StaAud = 3)) AS c
WHERE (c.InventarioAnteriorANT + c.ComprasANT + c.AjustesANT - c.CreditosANT - c.InventarioActualANT)<> (c.InventarioAnteriorACT + c.ComprasACT + c.AjustesACT - c.CreditosACT - c.InventarioActualACT)
) t1 GROUP BY CODTIENDA,TIENDA, CODCP ,CODITEM,ITEM,VentasAnterior ,VentasActual
saludos!