Subject Re: Query returns invalid result
Author Roman Rokytskyy
> The intention is to find out the difference between the count of
> rows with P and the count of rows with X, filtered by various
> criteria such as a given DateSbm and/or AccountId.
> ...
> Any suggestions on a correct SQL statement?

Try

SELECT
(SELECT COUNT(CPR1.CLAIMSTS)
FROM CLAIMSPAIDREVERSED CPR1 WHERE CPR1.DATESBM>=?
AND CPR1.DATESBM<=?
AND CPR1.CLAIMSTS='P'
AND CPR1.ACCOUNTID=?
) - (SELECT COUNT(CPR2.CLAIMSTS) FROM
CLAIMSPAIDREVERSED CPR2 WHERE CPR2.DATESBM>=?
AND CPR2.DATESBM<=?
AND CPR2.CLAIMSTS='X' AND CPR2.ACCOUNTID=?
)
FROM RDB$DATABASE


Roman