Alyanto
asked on
Finding the default value of a stored procedures arguments
I have come to a point in my script that I seem unable to overcome. I want to know what the default value of a procs argument is. sys.parameters seems not to reflect this, I can see in a scripted proc some of its arguments have default values and some do not but when I use the default_value = Null and Has_default_value = 0 for all arguments. Can anyone point me in the direction of a solution for this?
SQL SERVER 2012 is being used.
SQL SERVER 2012 is being used.
SELECT SCHEMA_NAME(SCHEMA_ID) AS [Schema],
SO.name AS [ObjectName],
SO.Type_Desc AS [ObjectType (UDF/SP)],
P.parameter_id AS [ParameterID],
P.name AS [ParameterName],
TYPE_NAME(P.user_type_id) AS [ParameterDataType],
P.max_length AS [ParameterMaxBytes],
P.is_output AS [IsOutPutParameter]
FROM sys.objects AS SO
INNER JOIN sys.parameters AS P
ON SO.OBJECT_ID = P.OBJECT_ID
WHERE SO.OBJECT_ID IN ( SELECT OBJECT_ID
FROM sys.objects
WHERE TYPE IN ('P','FN'))
AND SO.name = 'ProcsNameHere'
ORDER BY [Schema], SO.name, P.parameter_id
ASKER
The procs we already have do have default values against a large number of the arguments, and often the default is null but sometimes it is mandatory and no default is given.
what I want to achieve is identifying which arguments are mandatory by thier lack of a default. I am looking for a system table to give either the information or clues to a logical argument to determine whether it is or it is not.
what I want to achieve is identifying which arguments are mandatory by thier lack of a default. I am looking for a system table to give either the information or clues to a logical argument to determine whether it is or it is not.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think the issue is that has_default_value in sys.procedures is unclear in its origins. Where as is_output corrolates clearly to its purpose a parameter with Param INT = NULL I would expect as having is_output = 0 but has_default_value = 1 is what I would also expect. Perhaps the table needs some sort of refresh to bring it upto date.
However what you have provided has given me a new avenue to explore and may thanks for the excellent support given
However what you have provided has given me a new avenue to explore and may thanks for the excellent support given
ASKER
I will look into "EXEC sp_refreshsqlmodule @spname" from this point on to see if I can coax the meta data in.
If you need this nailed down then you can define a default value in your procs, see the '= value' in the below code. Using this, if a NULL value is passed the SP will use the default value instead
Open in new window