I want no results for null when nothing matches
select t.range as [PriceRange], count(1) as [BooksCount]
from (
select case
when Offer > 3 and offer < 5
then 'Criteria1'
when offer >= 5 then 'Criteria2'
END as range
from BookDetailsMaster) t
group by t.range
This query return value for null range also, because of which it is taking long time to execute. I want it should not search anything in database if no case matches.
If I apply a filter where t.range is not null it is not returning the null values but the query is taking long, so I am doubting it is still checking for no match criteria but while returning result it is not returning that value.
Id Offer
1 2
2 4
3 5
4 6
5 7
6 1
PriceRange BooksCount
-------------------------
Criteria1 1
Criteria2 3
The doubt is it is also making query for a null criteria
You should do this simple condition