I use this tactic in some projects. If users cannot change the SQL syntax in the database, I donβt see a big security problem. If so, you should evaluate SQL before using it.
Also, if only a few parameters in the query differ for different rows, you can simply save them and run them in a stored procedure or create dynamic SQL from the values.
I used this to collect and transfer data to another data format. The source data was stored in very different data formats and database designs. The target format has always been the same EAV model.
I used stored SQL as part of an entire SQL statement that transfers data from one batch of data in one day.
Since I did not want the mess of stored procedures to increase over time, I selected this option.
I also wanted to keep a history of the SQL statements used for each batch of data for future reference when I changed SQL queries in the future.
The ability to use SP will continue to be viable, although I donβt know how to do it now to keep a history of SQL statements used over time.
source share