August 3, 2010 at 9:15 am
I'm trying to determine all the procedures that utilize dynamic sql.
The only way I've come up with is:
select sasm.*
from sys.all_sql_modules sasm
JOIN sys.objects so
ON so.object_id = sasm.object_id
where sasm.definition like '%sp[_]executesql%'
and so.is_ms_shipped = 0
However, this only gets code that uses sp_executesql.
I'd like to find procedures that use exec (), execute (), etc.
The problem with this is that there may be 0-n spaces between the keyword and the parenthesis.
If I just look for "exec", I can get all procedures that just call another procedure.
So, does anyone have a good method to identify all procedures that are using dynamic sql?
Thanks!
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 3, 2010 at 9:32 am
can't you ignore the second bracket in your search?
alternatively search for
exec('
and
exec(@[a-Z]
August 3, 2010 at 4:41 pm
This is slow but it works ...
select sasm.*
from sys.all_sql_modules sasm
JOIN sys.objects so
ON so.object_id = sasm.object_id
where (replace(sasm.definition, ' ', '') like '%exec(%'
or replace(sasm.definition, ' ', '') like '%execute(%')
and so.is_ms_shipped = 0
August 3, 2010 at 5:29 pm
bt, this looks promising. I don't really care about the speed - it's a one-off thing.
I just need to identify all the code with dynamic sql.
I'll try it out tomorrow, and let post back with how it works.
(Just what I love about this site. I was so focused on identifying it one way with multiple spaces, and I never even considered yanking out all the spaces.)
Thanks!!!!!
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply