Código SQL:
Ver originalSELECT A.empresa,A.productor,A.ALTA,A.BAJA
FROM (
SELECT empresa,productor,(SELECT MAX(fecha1)[ALTA]
FROM NINC WHERE empresa=001 AND clave=5 AND fecha1<=@fFecha),
(SELECT MAX(fecha1)[BAJA] FROM NINC WHERE empresa=001 AND clave=6 AND fecha1<=@fFecha)
FROM ninc
WHERE empresa=001 AND clave=5 AND fecha1<=@fFecha
GROUP BY empresa,productor
) A
WHERE A.ALTA > ISNULL(A.BAJA,1)