sum( case dbo.D_VEHICLE_STATUS.LIFECYCLE_STATUS_CODE
when '0' then dbo.F_VEHICLE_STATUS.VEHICLE_STATUS_UNITS
else sum(
( case when dbo.D_PORT.PHYSICAL_PORT_CODE = 'PMA' then
dbo.F_VEHICLE_STATUS.VEHICLE_STATUS_UNITS
else 0 end ) end )
every case must have a end.