Hi,
I have two queries that are almost alike. The difference is that one makes a few additional joins and projects a few additional columns from those additional joins. I'd like to avoid the duplication in the parts where they are alike.
I thought of making a view of the common part, then using that in two stored procedures. One would simply run the view (FROM view), and the other would run the view with the additional joins (From view JOIN ... ).
But here's the thing about this approach: Both of the original stored procedures perform a selection operation (WHERE clause) that is defined by a parameter. With the new approach, that parameter has to remain in the (new) stored procedures (that I know, a view cannot have parameters...?), so the operations in the view no longer include a selection operation. I'm not sure how the SQL engine does its processing, but I imagine that this will decrease the efficiency of the new stored procedures relative to the original ones. Will it? And, if so, is my only option a trade-off between processing efficiency and development/maintenance efficency? Is there a better way?
Thank you,
I have two queries that are almost alike. The difference is that one makes a few additional joins and projects a few additional columns from those additional joins. I'd like to avoid the duplication in the parts where they are alike.
I thought of making a view of the common part, then using that in two stored procedures. One would simply run the view (FROM view), and the other would run the view with the additional joins (From view JOIN ... ).
But here's the thing about this approach: Both of the original stored procedures perform a selection operation (WHERE clause) that is defined by a parameter. With the new approach, that parameter has to remain in the (new) stored procedures (that I know, a view cannot have parameters...?), so the operations in the view no longer include a selection operation. I'm not sure how the SQL engine does its processing, but I imagine that this will decrease the efficiency of the new stored procedures relative to the original ones. Will it? And, if so, is my only option a trade-off between processing efficiency and development/maintenance efficency? Is there a better way?
Thank you,