the first one does a filter on whole query based on date range whereas second one does it inside the count. so there are equivalent. But reason why you didnt get correct result in second case is because of a typoit should beSELECTCOUNT(CASE WHEN A.statk_auf_datum >= {d '2013-01-01'} AND A.statk_auf_datum <= {d '2013-03-31'} THEN B.STATK_AUFNR ELSE 0NULL END) AS besucheFROM(SELECT A.STATK_AUFNR,A.STATK_BEZIRK,A.STATK_KDNR,A.STATK_BES_ART,A.STATK_AUF_DATUM,A.STATK_AUF_WERT AS brutto,Sum(B.STATP_FAKT_SUMME) AS nettoFROMGKKopf AINNER JOIN GKPos B ON A.STATK_AUFNR = B.STATP_AUFNR AND A.STATK_BEZIRK = B.STATP_BEZIRK) B
As 0 will still mean it will include it as valid record. if you want to use 0 for exclusion you should be applying SUM rather than COUNTieSELECTSUM(CASE WHEN A.statk_auf_datum >= {d '2013-01-01'} AND A.statk_auf_datum <= {d '2013-03-31'} THEN 1 ELSE 0 END) AS besucheFROM(SELECT A.STATK_AUFNR,A.STATK_BEZIRK,A.STATK_KDNR,A.STATK_BES_ART,A.STATK_AUF_DATUM,A.STATK_AUF_WERT AS brutto,Sum(B.STATP_FAKT_SUMME) AS nettoFROMGKKopf AINNER JOIN GKPos B ON A.STATK_AUFNR = B.STATP_AUFNR AND A.STATK_BEZIRK = B.STATP_BEZIRK) B
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs