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.

here's image of 2 results same t-sql batch.

the error in second case caused order clause, since engine cannot evaluate order of null value.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -