Need to find the length of stay. Using datediff to find the number of days between admission and discharge and if the admission date is before the select parameter startdate value then use the parameter value.
Tried this, case statement works fine outside the datediff function but not within it any suggestions.
datediff(day, case when ia.eventstartdate < @startdate then @startdate else ia.eventstartdate end as 'ia_eventstartdateB' ,id.eventstartdate) as los1,