One other point - generating SQL code inside of the application really hurts the chance of reusability in other applications hitting the same database.
By placing the code in a stored proc, the level of difficulty in exposing this as an API to multiple applications does down.