why are these returning different results?

  • Ok, this has me completely baffled. Why do these two queries return a different count (first:168, second:197)?

    SELECT COUNT(CASE WHEN d.sd_spvsrrev IS NULL AND (
    d.[sd_spvsrrevdate] IS NULL OR
    (d.[sd_spvsrrevdate]<'4/21/2006' AND d.[sd_spvsrrev]='S') OR
    (d.[sd_spvsrrevdate]>='4/21/2006' and d.[sd_spvsrrev] in ('S', 'U'))
    )THEN [sd_itid] END) AS i
    FROM dbo.[intake] i WITH (NOLOCK)
    JOIN dbo.[reportaccpri] r WITH (NOLOCK) ON (i.[itid]=r.[rapintakeid])
    JOIN dbo.[family_service_disp] d WITH (NOLOCK) ON (i.[itid]=d.[sd_itid])
    WHERE i.[itde] <> i.[itdc] AND r.[rapfinalrec]='Y'
    
    SELECT COUNT([sd_itid])
    FROM dbo.[intake] i WITH (NOLOCK)
    JOIN dbo.[reportaccpri] r WITH (NOLOCK) ON (i.[itid]=r.[rapintakeid])
    JOIN dbo.[family_service_disp] sd WITH (NOLOCK) ON (i.[itid]=sd.[sd_itid])
    WHERE i.[itde] <> i.[itdc] AND r.[rapfinalrec]='Y'
    AND sd.[sd_spvsrsub] IS NULL AND (
    sd.[sd_spvsrrevdate] IS NULL OR
    (sd.[sd_spvsrrevdate]<'4/21/2006' AND sd.[sd_spvsrrev]='S') OR
    (sd.[sd_spvsrrevdate]>='4/21/2006' and sd.[sd_spvsrrev] in ('S', 'U'))
    )
    

  • Wait, I think I found it. [sd_spvsrrev] IS NULL in the top, [sd_spvsrsub] in the bottom.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply