Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Can I use aggregate function within CASE?

$
0
0

The following query generates an error because I'm using MAX. Is there an alternative to this?

I can also store it in a variable, but I prefer, if possible, that it's all in the statement.

select  
case   
   when Field1 > 0 and max(Field1) > 0 then 'do something'
   when Field1 < 0 and max(Field1) < 0 then 'something else'
end as 'FIELD'  
from TABLE order by Date

Thanks for your help.


VM



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>