sql - Adding second CASE WHEN column changes query result completely? -
i have following queries:
1
select top 1 case when latency=-1 'down' else 'up' end status @pings_temp order datetime desc; 2
select top 1 case when latency=-1 'down' else 'up' end status, case when latency=-1 ( select top 1 datetime @downtimes_temp order datetime desc ) else null end datetime @pings_temp order datetime desc; the first should yield 'up' , second should yield 'up' in first column , null in second.
however, doesn't happen. first query performs how should, adding second column select makes query go berserk, causing read out 'down' , date seemingly random column.
the error in second case caused order clause, since engine cannot evaluate order of null value.
Comments
Post a Comment