Yes. you can use dynamic sql, but I personally like stored procedures.
1) If you use MS SQL Server, it will generate a query plan that should allow the stored procedure to execute faster than simple dynamic sql.
2). It is best to fix the error in the stored procedure, especially if your application calls this procedure in several places.
3) I am pleased to encapsulate the database logic in the database, and not in the embedded sql file or application configuration file.
4) Creating a stored procedure in the database will allow the SQL server to execute some syntax and check validation during development.
Jeremy
source share