I am trying to write a SQL script that will pull up information on where certain data is stored (i.e. which server and DB it is in). I have the part where it is pulling up the information and putting it into a separate DB on the same server, but much of the data that I'm wanting to collect is on other servers. Is there a way in the same script to connect to several different DB's on several different servers to get the data that I want. Essentially I'm trying to get Names, emails and phone numbers for people in our various DB's. Here is what I have so far:
if OBJECT_ID('tempdb..#TrainingSessionInfo') is not null
drop table #TrainingSessionInfo
if OBJECT_ID('PSBackup.dbo.InvestigoUniversitySessions','U') is not null
drop table PSBackup.dbo.InvestigoUniversitySessions
declare @StartDate date = null
,@EndDate date = null
set @StartDate = '1/1/2014'
set @EndDate = '6/17/2014'
--exec spGetTrainingSessionInfo @StartDate,@EndDate
create table #TrainingSessionInfo(cntID int,datDate datetime,strDesc varchar(255),strFirmID varchar(255),strTrainer varchar(255)
,meetingID varchar(255),Attendees int)
insert into #TrainingSessionInfo
exec spGetTrainingSessionInfo @StartDate,@EndDate
create table PSBackup.dbo.InvestigoUniversitySessions (lngSessionID int
,strUserID int
,strFirmID varchar(255)
,cntIF int
,strDSNServer varchar(255))
insert into PSBackup.dbo.InvestigoUniversitySessions (lngSessionID,strUserID,strFirmID,cntIF,strDSNServer)
select lngSessionID
,strUserID
,strFirmID
,cntID
,s.strDSNServer
from tblTrainingSessionSignUp tss
join Sites s on s.FirmID = tss.strFirmID
where tss.lngSessionID in(select cntID from #TrainingSessionInfo)
select * from PSBackup.dbo.InvestigoUniversitySessions order by lngSessionID desc,strFirmID,strUserID desc