I need help on performance of a query I have that is very slow.
The query is doing a case on a column in order to return a different text value
based on the number.
If I had a table with values 1-5 and 8-10 If something has a value of 1 it should display ‘Apple’ or if it is 2 it must display ‘pear’ if it is anything other than 1-5 then it is ‘other’. Currently a case statement is being used, but I heard that functions on a query makes it slower.
All I want is the ‘Wording’ to appear instead of the the number but because the table is so big it feels to me like it is iterating each row just to determine what to display.
Is there a faster way of doing this.I considered doing a join, which seems like it would work nice, but I dont know how to write ‘other’ for anything other than 1-5
A
casestatement is not a function. User-defined functions do have additional overhead in some versions of SQL. You don’t, as a general rule, need to worry about the overhead for built-in functions.You could do this with a join as:
I would expect the case statement to be marginally faster though.