erikdarlingdata/DarlingData

sp_QuickieStore: @get_all_databases = 1 and @procedure_name seem incompatible.

ReeceGoding opened this issue · 0 comments

Version of the script
4.5

What is the current behavior?
On a server that has many databases, get the name of a procedure that is in only one of your databases. Pass said name in to the @procedure_name parameter of sp_QuickieStore. Also pass in @get_all_databases = 1. You will find that the correct procedure is found in the results for the database that has the procedure, but the other databases act as if you did not pass in the @procedure_name parameter. Instead, they return many rows that have nothing to do with the procedure in question.

Setting @debug = 1 will reveal that the value of @procedure_name_quoted appears correct and nothing in the code jumped out to me as being obviously wrong.

Given that passing in a database that does not have the desired procedure when using @database_name rather than @get_all_databases prints out an error message and early exits, I suspect that @get_all_databases has been set up to ignore the early exit and incorrectly carries on as if @procedure_name was not specified. The logic for that seems to be about here. I tried adding in a CONTINUE, but it wasn't sufficient. Copy and pasting in these truncates and the FETCH NEXT as well as adding in CONTINUE worked, but it seemed so ugly that I decided that it was best to leave the PR to more skilled hands. I think that the truncates aren't actually needed, but not including them here strikes me as a path to brittle code.

If the current behavior is a bug, please provide the steps to reproduce.
See above.

What is the expected behavior?
Regardless of database, only the rows from the procedure named by @procedure_name should be returned.

Which versions of SQL Server and which OS are affected by this issue? Did this work in previous versions of our procedures?
I doubt that this is version dependent.