How about this:
select MIN(Measurement), (Case WHEN len(min(measurement)) = 6 then '0000' ELSE '000' END) as [Min] from LeachingView where DateTimeStamp > '2011-01-01' and measurement > 0
In addition, you mixed aggregates with non-aggregates.
Update
You should just lose 'NonDesMin' . Explanation: when you enter a "variable" immediately after CASE , you may have your WHEN clauses comparing equality with your variable. So your SQL could also be like this:
select MIN(Measurement), (Case len(min(measurement)) WHEN 6 then '0000' ELSE '000' END) as [Min] from LeachingView where DateTimeStamp > '2011-01-01' and measurement > 0
However, you are using CASE in this format:
CASE SomeField WHEN 1 then 'One' WHEN 2 the 'Two' else 'Three or more' end
source share