I'm trying to print 'no data' for the null values in the tavg int datatype column but I keep getting a conversion failed error in the presence of the "then sum((tmin+tmax)/2)" portion. Any help?
select
Case
when (tavg > -59 and tmin is NULL and tmax is NULL ) then tavg
when (tavg > -59 and tmin is NULL and tmax > -59) then tavg
when (tavg is null and tmin >-59 and tmax > -59) then sum((tmin+tmax)/2)
when (tavg is null and tmin is null and tmax is null) then 'No data'
else cast(tavg as varchar(50)) end as 'avg_temp',
case
when tmin is null then 'No data' else cast(tmin as varchar(50)) end as 'Minimum Temperature',