Ver originalSELECT V.ID, V.FECHA, V.VENTA, MIN(ABS(DATEDIFF(D,V.FECHA,C.FECHA)))FROM VENTA VINNER JOIN COSTO C ON V.ID = C.IDGROUP BY V.ID, V.FECHA, V.VENTA