I have a situation where if the column value is less the 1 then I have to show NO
as column value, else YES
. I am using CASE
statement for this. But after applying CASE
statement query is taking to much time to execute. Is there any alternate way of achieving this without using CASE
statement?
Asked
Active
Viewed 3,391 times
2
-
2Post your entire query. Looks like it's not the `CASE` statement that's causing the long execution time. – Felix Pamittan Sep 22 '15 at 08:32
-
Add your code in the post. – Ullas Sep 22 '15 at 08:32
-
Post your query and some sample data – Raj Sep 22 '15 at 08:32
-
but when i am removing the case statement.it is taking less time.. – gkarya42 Sep 22 '15 at 08:34
-
@gkarya42, without looking at your query, we cannot answer your question. Unless your `CASE` statement is executing another query, there's no reason it will slow down the entire query. – Felix Pamittan Sep 22 '15 at 08:39
-
also add the datatype of the involved columns – Paolo Sep 22 '15 at 08:44
-
I have posted the query.Please help – gkarya42 Sep 22 '15 at 08:52
-
I'd say the problem you have is all those selects back to the same table in the different columns, including the case statement. You should probably re-factor the whole query. – James Z Sep 22 '15 at 14:35
1 Answers
2
It's difficult to say without seeing the initial code. But with a simple Yes/No it might be worth looking into two selects with a union all:
(1) First select where value < 1
union all
(2) Second select where value >= 1

Ralph
- 9,284
- 4
- 32
- 42