'How can I extract parameter names and values from within a currently running stored procedure in SQL Server?

I'm building a stored procedure to log table/procedure and need to be able to pull (not specific to current stored procedure) all parameter names and values. This would then be inserted into that Log table.

I'm hoping there is a one-liner (or a loop) function that will grab the info.

I've only seen articles about accessing sys.objects to identify parameters so far and this seems counter-productive and will be a performance hit.

This will be run on multiple stored procedures so can't require manually naming/calling the parameters.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source