-1

Currently work with multiple servers and need to return the results in a table, how can I do? I intend to get data from each bank and return all through a single procedure. Example, caught available space of the server and return in table format. You must be in .NET

Fabiano Carvalho
  • 461
  • 1
  • 4
  • 16

1 Answers1

0

First create the links to other server

Example:

USE [master]
GO

EXEC master.dbo.sp_addlinkedserver 
@server = N'SecondServer', 
@srvproduct=N'SQL Server' ;
GO

EXEC master.dbo.sp_addlinkedsrvlogin 
@rmtsrvname = N'SecondServer', 
@locallogin = NULL , 
@useself = N'True' ;
GO

Then you can create procedure that can query multiple server.

Example:

CREATE PROCEDURE procedureName
(
  @dateFrom datetime,
  @dateTo datetime
)
AS

BEGIN

SELECT * FROM  CurrentServerName.DatabaseName.TableName
UNION
SELECT * FROM SecondServerName.DatabaseName.TableName;

END
Aizaz Ahmed
  • 210
  • 1
  • 6
  • Correct. It's not just these information I need, I need some information level system, which is idel use any IDE So I intend to do in .NET – Fabiano Carvalho Oct 26 '15 at 16:30
  • Thats was an reply to your question. Personally I would not go with Linked server. Follow this http://stackoverflow.com/questions/14055314/accessing-multiple-databases-from-sql-server-2008-r2-in-my-windows-application – Aizaz Ahmed Oct 26 '15 at 17:07