Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a query over multiple databases and across servers

Status
Not open for further replies.

angiem

MIS
Sep 29, 2000
116
0
0
CA
I need to run a query over multiple databases and across servers. I'm using sp_addlinkedserver and sp_addlinkedsrvlogin and the code I'm using is below currently it's only bringing back the results from the server where the query resides and not the linked server how do I tell it which server to use

Code:
set @cmd1 =
   'if ''?'' like ''abc_'' or ''?'' like ''abcd%''  
insert into tempcounts(dbname, cmonth, cyear, totalcount)
 Select ''?'', month(datereceived), year(datereceived) , count(*)
From  [?]..tblname
group by month(datereceived), year(datereceived)' 
exec sp_MSforeachdb @command1=@cmd1

Angie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top