I have a problem with WHERE clause branch in a sp. Here is the sample:1.select Sum(ProdNum) ... from Table1where Code = @Code and Left(Model, 4) = 'ABCD' ...2.select Sum(ProdNum) ... from Table1where Code = @Code and Right(Model, 4) = 'ABCD' ...

there are about 100 pieces of statements like those. When the @code values change the different statement is run, for example, if @code='M123' then it runs #1, @code='N321' then it runs #2, so forth. I am thinking is there any way like branch in c# or other better ways to simplify the codes, because the each WHERE clause is long, each select piece takes about 70 lines, or I can only write 100 stored procedures? Really appreciate your help!

2. Use dynamic SQL. Even though usually one would try to avoid dynamic sql if at all possible, this is one of those cases you might consider it.I prefer the lookup table, but you may need dynamic sql if your join condition changes for each lookup value (as in your example, it is RIGHT(Model,4) in one case and LEFT(Model,4) in another case. There is a discussion of the reasons for doing this and the safe way to do this at Gail Shaw's blog here: http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/