simplify if statement with stored procedure <p>i have a following stored procedure where i am repeating similar code. all i am doing is checking the condition based on Sample id1, sampleid2, and sample id3 to follow in similar fashion. The value of 'y' goes on till about it reaches 10, so it's going to be a big 'if' condition based statements. i was trying to see if a better solution could be put in place. thanks.</p> <pre><code>@select = 'select * from tbl Sample......' if(x = 1 and y=1) set @where = 'where Sample.id1 &gt;=1 and &lt;=10' if(x = 1 and y=2) set @where = 'where Sample.id1 &gt;=11 and &lt;=20' if(x=2 and y=1) set @where = 'where Sample.id2 &gt;=1 and &lt;= 10' if(x=2 and y=2) set @where = 'where Sample.id2 &gt;=11 and &lt;=20' if(x=3 and y=1) set @where = 'where Sample.id3 &gt;=1 and &lt;=10' if(x=3 and y=2) set @where = 'where Sample.id3 &gt;=11 and &lt;=20' //increment goes on exec(@select+@where) </code></pre>