The following query that I have is encountering a divide by 0 error:
select pp.building_name,
ld.tenant_trading_name,
tenancy_reference,
ld.turnover_threshold,
ld.percentage_rent,
ld.income_base_rent_ach,
ld.income_base_rent_ach / ld.percentage_rent as correct
from
lease_deal.lease ld
inner join property.property pp
on ld.building_id = pp.building_id
where
(ld.income_base_rent_ach / ld.percentage_rent ) <> ld.turnover_threshold
and lease_status = 'APPROVED'
and ld.progenesis_load_date is null
order by pp.building_name
I’ve tried to correct this by doing the following – but I’m receiving a syntax error and I’m unsure why? What is syntactically incorrect here?
select pp.building_name,
ld.tenant_trading_name,
tenancy_reference,
ld.turnover_threshold,
ld.percentage_rent,
ld.income_base_rent_ach,
ld.income_base_rent_ach / ld.percentage_rent as correct
from
lease_deal.lease ld
inner join property.property pp
on ld.building_id = pp.building_id
where
case when ld.percentage_rent = 0
then 1=1
else ((ld.income_base_rent_ach / ld.percentage_rent ) <> ld.turnover_threshold)
end
and lease_status = 'APPROVED'
and ld.progenesis_load_date is null
order by pp.building_name
How about replacing
with