SELECT
Schema_name(Schema_id)+
'.'
+Object_Name(M.Object_id) StoredProceduresWithDynamicSQL
FROM
sys.sql_modules M
JOIN
sys.objects O
ON
M.object_id = O.object_id
WHERE
definition
LIKE
'%CREATE PROC%'
AND
(definition
'%SP_ExecuteSQL%'
OR
'%EXEC%'
)
EXCEPT
StoredProcedure
(
+Object_Name(M.Object_id) StoredProcedure
)) tmp
CROSS
APPLY sys.dm_sql_referenced_entities (StoredProcedure,
'OBJECT'
);
Richard Mueller edited Revision 9. Comment: Modified title, fixed minor typo
Naomi N edited Revision 3. Comment: Minor edit
Naomi N edited Revision 2. Comment: Minor edit
Adding this to the August TechNet Guru competition. Thanks!
Similar to: social.technet.microsoft.com/.../18716.t-sql-how-to-find-stored-procedures-that-use-dynamic-sql.aspx