Case Statement Issue

I am hoping you can help me. The person that created this statement is no longer in the company.

The part of the case statement that is not working is this below. They were trying to pull anything that had a turn around date greater than 20 days. But this is still pulling dates that are under 20.

When clm_att2= 'NA' and datediff(day,clm_rcvd,clm_dout) + 1 >= 20 then 'Maximum Turn Around Time

Below is the full Case Statement

case
When ((BS.clme_fild = 'BCBSST' and clm_att4 = 'NO') or (o.StatusCode = 124990019 and clm_att4 = 'OK')) and (clm_att2 = 'NA' or clm_att2 is null) then 'Blue Squared'
when clm_att2= 'NA' and clm_meda4 > 0 and cast((cast(clm_meda4 as decimal(9,2))/cast(clm_tchg as decimal(9,2))) * 100 as decimal(9,2)) <= 25.00 then 'Allowable <= 25% of TotalCharges'
when clm_att2= 'NA' and clms_pos in ('41','42') then 'EMS'
When clm_att2= 'NA' and datediff(day,clm_rcvd,clm_dout) + 1 >= 20 then 'Maximum Turn Around Time' ---was 10 days changed it to 20 per Mike on 7/11/2018
when (clm_att2 = 'NA' and clm_att4 = 'OK') or (clm_att2 is NULL and clm_att4 = 'NO' ) then 'All Other Specialities' end [ClaimCategory] ---It was just this for all other specs (clm_att2= 'NA')4-12-2018

Please provide

  • table definitions in the form of create statements
  • sample data in the form of insert statements
  • expected output from the sample data you provide
  • your query so far

The case expression does not filter out data - you need to include something in the where clause.