1: 2: 3: 4: 5: 6:
set @Command = 'USE [' + @d + '] SELECT db_name(), count(*) FROM [' + @d + '].dbo.table where [Column] = ''Value'';' exec (@command)