Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Sys processes

Author  Topic 

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2010-02-17 : 15:30:25
How can we display systemprocesses from multiple sql servers in a single querry? e.g i have sql1,sql2,sql3

I tried following but it works on single server.

select @@servername ,a.[name],b.Status,b.hostname
from sys.databases a, sys.sysprocesses b
where a.database_id=b.dbid

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2010-02-17 : 19:43:43
Anybody have idea?
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-02-17 : 22:40:20
If all the servers(you want to query) are linked then you can try using the four part name.

select @@servername as ServerName ,a.[name],b.Status,b.hostname
from sys.databases a, sys.sysprocesses b
where a.database_id=b.dbid
Union
select 'NextServer' as ServerName,a.[name],b.Status,b.hostname
from [NextServer].master.sys.databases a, [NextServer].master.sys.sysprocesses b
where a.database_id=b.dbid

I am not sure whether this is the best way or not..

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-17 : 23:53:41
You'll either need linked servers for each of the servers you want to remotely query, or you could write a CLR object on one server that queries them all one at a time and then puts them all into a single result set.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-19 : 16:25:39
Use @@SERVERNAME to get the server's name including the instance name.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-19 : 17:52:10
Sorry I posted without thinking. @@SERVERNAME will only work for the local server. Use sys.servers instead.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-02-21 : 05:02:37
quote:
Originally posted by rudba

Thanks i got the server name but i have more than 2 server so i get same count from both. I tried below script





On which server you are executing this query ?
In case you are executing the query on [sql-edd3] server then you will get same result. Make sure that you are executing the query on other server ( and not [sql-edd3] ) to get different output.
Please check and confirm.
Go to Top of Page
   

- Advertisement -