There are a few ways to hide a stored procedure in a stored procedure in SQL Server, but one common approach is to use dynamic SQL. Dynamic SQL allows you to generate and execute T-SQL statements at runtime, which can be used to hide the underlying stored procedure. Here is an example of how to hide a stored procedure named “usp_HiddenProcedure” in a stored procedure named “usp_WrapperProcedure”:
CREATE PROCEDURE usp_WrapperProcedure
AS
BEGIN
DECLARE @sql NVARCHAR(MAX)
SET @sql = 'EXEC usp_HiddenProcedure'
EXEC sp_executesql @sql
END
In this example, the “usp_WrapperProcedure” stored procedure generates and executes a dynamic SQL statement that calls the “usp_HiddenProcedure” stored procedure. The “usp_WrapperProcedure” stored procedure can be executed by users, but the underlying “usp_HiddenProcedure” stored procedure is not directly accessible.
It’s worth noting that this approach could have limitations and might not be the best choice in all cases. It’s also important to keep in mind that this method only hides the stored procedure, but it does not provide any security or access control for the stored procedure, so it should not be used as a security measure, it’s best to use it for encapsulation and abstraction purposes.