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

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -