• Looks like logic is coded in a complicated way, too much use ot temp tables. Sorry for not looking in depth but you can create a dynamic query to execute a particular block of SQL statements based on parameter selection.