Query to set variable depending on query results

You can use conditional aggregation:

select @dev = min(case when value = 0 then 1 else 2 end)
from tempresults
where point in ('ZM1', 'ZM1-2')

Basically the case expression turns 0 values to 1 and others to 2; all that is left to do is compute the minimum computed value in the group. If there is any 0, you get 1, else 2.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top