declare @DBName nvarchar(30) set @DBName = 'DBName' SELECT p.name as procName , COALESCE(d.referenced_server_name , N'') as refServer , COALESCE(d.referenced_database_name, @DBName) as refDB , COALESCE(d.referenced_schema_name , N'dbo') as refSchema , d.referenced_entity_name as refObject FROM DBName.sys.sql_expression_dependencies AS d join DBName.sys.procedures as p on d.referencing_id = p.obj..