I have a very large application and it would create headache to change every call to this procedure, so I am attempting to make an optional parameter to the procedure. Here are the top two lines of the procedure
ALTER PROCEDURE [dbo].[sp_get_entity_list]
@entityid int , @entitycat int, @adminTab bit = 0, @root int = 0
When calling the procedure in code, usually it is called
"EXEC sp_get_entity_list " & EntityID & ", " & EntityCAT
but in a few cases I need to pass a bit type parameter to show it came from a different location – i am calling this by using
"EXEC sp_get_entity_list " & EntityID & ", " & EntityCAT & ",1"
Am I doing something wrong? I am unsure if this is the correct way to pass an optional parameter, I want adminTab to be set to false (or null, does not matter), unless I pass the optional parameter. Thanks.
I think its better to include the name of each parameter when executing a stored procedure like:
This means SQL knows exactly which parameters you are referring to.
Therefore, if you have optional parameters, you don’t need to include every single one, if you wish to use the default value: