



CREATE procedure DBO.GetModulesOnDB(@module varchar(100), @Databasename varchar(100) = '') as
SET NOCOUNT ON

declare @dbid int

if @databasename = '' 
  select @dbid = dbid from master..sysprocesses WITH (nolock) where spid = @@spid
else
  select @dbid = dbid from master..sysdatabases WITH (nolock) where name = @databasename

select distinct program_name, hostname, hostprocess 
from master..sysprocesses WITH (nolock) 
where dbid = @dbid
      and program_name like '%' + @module + '%'

