Oh ok glimbeek, so you're looking for any queries that execute from AP001 onto DB001 which we are monitoring, but AP001 does not house the DB itself and is not being individually monitored either.
I have a question for you then, if you do a select * from COND to find the DBID (column ID) of DB001, what do you see when you do a select * from conm_XX (where XX is the ID of DB001 from COND)? I'm hoping you can see the name of AP001 in that list. If you can, than you can alter the query this way:
ALTER PROC [dbo].[TopSQLforMSSQLMachine]
(@FROM_DATE VARCHAR(16), @TO_DATE VARCHAR(16), @APPLICATIONSERV VARCHAR(50), @MACHINENAME VARCHAR(50))
AS
BEGIN
SET @sql =
N'SELECT ' +
@id + N',
ISNULL(N.NAME, SW.IZHO) HASH_OR_NAME,
SUM(SW.QP/100) TIMESECS,
ST.ST SQLTEXT ' +
'FROM dbo.CONSW_' + @id + ' SW LEFT OUTER JOIN dbo.CON_SQL_NAME N ON SW.IZHO = N.HASH ' +
'LEFT OUTER JOIN dbo.CONM_' + @ID + ' MM ON SW.PWMY = MM.ID ' +
'LEFT OUTER JOIN dbo.CONST_' + @id + ' ST ON SW.IZHO = ST.H ' +
'INNER JOIN dbo.CONU_' + @id + ' U ON SW.XCUW = U.ID ' +
'WHERE SW.D BETWEEN ' +
'CONVERT(DATETIME,' + '''' + @FROM_DATE + '''' + ', 101) AND ' +
'CONVERT(DATETIME,' + '''' + @TO_DATE + '''' + ', 101) ' +
' AND MM.NAME = ''' + @APPLICATIONSERV + '''' +
' Group by N.NAME, SW.IZHO, ST.ST
Order by SUM(SW.QP/100) desc'
insert into @HostGatheredCursorData
EXEC (@SQL)
You may have to adjust the quotes a bit or possibly fully qualify the MM.NAME = portion of the where clause, I ended up typing those additions in Thwack vs SQL while my VM's are getting fixed up. Adding the CONM table and adding the computer name into the where clause should give you what you're looking for as long as the above statement about checking those tables rings true. Is that closer to what you were looking for? If not, would it be ok to get a go to meeting scheduled and then I can see your screen / instance and we can talk out what you're looking for in case I'm missing something? My email should be in my bio but we can be reached by support@confio.com too.