Performance improvement to a big if clause in SQL Server function
Posted
by Miles D
on Stack Overflow
See other posts from Stack Overflow
or by Miles D
Published on 2010-03-15T21:44:58Z
Indexed on
2010/03/15
21:49 UTC
Read the original article
Hit count: 187
I am maintaining a function in SQL Server 2005, that based on an integer input parameter needs to call different functions e.g.
IF @rule_id = 1
-- execute function 1
ELSE IF @rule_id = 2
-- execute function 2
ELSE IF @rule_id = 3
... etc
The problem is that there are a fair few rules (about 100), and although the above is fairly readable, its performance isn't great. At the moment it's implemented as a series of IF's that do a binary-chop, which is much faster, but becomes fairly unpleasant to read and maintain. Any alternative ideas for something that performs well and is fairly maintainable?
© Stack Overflow or respective owner