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
Angie
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