<whentest="Blocks.largeFormat !=null and Blocks.format == null">
join FORMAT f ON b.housing_estates_id = f.housing_estates_id and f.large_format = #{Blocks.largeFormat}
join `format` f ON b.housing_estates_id = f.housing_estate_id and f.large_format = #{Blocks.largeFormat} and f.status_cd=1000 and b.status_cd = 1000
</when>
<whentest="Blocks.largeFormat ==null and Blocks.format != null">
join FORMAT f ON b.housing_estates_id = f.housing_estates_id and f.format = #{format}
join `format` f ON b.housing_estates_id = f.housing_estate_id and f.`format` = #{Blocks.format} and f.status_cd=1000 and b.status_cd = 1000
</when>
<whentest="Blocks.largeFormat !=null and Blocks.format != null">
join FORMAT f ON b.housing_estates_id = f.housing_estates_id and f.format = #{format} and f.large_format = #{Blocks.largeFormat}
join `format` f ON b.housing_estates_id = f.housing_estate_id and f.`format` = #{Blocks.format} and f.large_format = #{Blocks.largeFormat} and f.status_cd=1000 and b.status_cd = 1000
</when>
<otherwise>
where b.status_cd = 1000
</otherwise>
</choose>
and b.housing_estates_id = #{Blocks.housingEstatesId}