1. Use Undocumented procedure
EXEC sp_msforeachdb
'if exists(select ''?'' from ?.sys.objects where name=''your_procedure_name'')
select ''?'' from ?.sys.objects where name=''your_procedure_name'''
2. Use Dynamic SQL
declare @sql varchar(max)
set @sql= ''
select
@sql=@sql+' select '''+name+''' as database_name from '+name+'.sys.objects where name =''procedure_name'' union all' from sys.databases
select @sql=substring(@sql,1,len(@sql)-9)
exec(@sql)
Thank you samy
ReplyDelete