Thursday, May 6, 2010

Find a Sepecific parameter type in all storedprocedures

some times we may require to find all the stored procedures where a specific dataype is used as a parameter or where a specific parameter name is used .
we can search those strored procedures using "sys.all_parameters","systypes","sys.objects"
say we want to know in which stored procedures data type smallint is used , we can do so by using the follwoing SQL

select schema_name(o.schema_id) schema_name, o.name obj_name, p.name param_name, t.name param_type
from sys.all_parameters p
join systypes t on t.xusertype = p.user_type_id
join sys.objects o on o.object_id = p.object_id
where o.type = 'P' -- type procedure
and t.name = 'smallint' -- data type
and o.is_ms_shipped = 0 -- user created
order by
schema_name(o.schema_id),
o.name;
AND
To search for a specific parameter name we can edit the above query as
select schema_name(o.schema_id) schema_name, o.name obj_name, p.name param_name
from sys.all_parameters p

join sys.objects o on o.object_id = p.object_id
where o.type = 'P' -- type procedure
and o.is_ms_shipped = 0 -- user created
and p.name='@OperatorId'
order by
schema_name(o.schema_id),
o.name;

No comments:

Post a Comment