Hi I am new to sql and currently developing a report in ssrs. I have a report I built using tables from a database (db 1) but also need information from a different dabatase (db 2), is there a way for me to select information in db 2 from db 1 where I have built my report but need 2 columns from db 2? Any help is greatly appreciated.
Asked
Active
Viewed 40 times
1 Answers
2
SQL Server offers something called Linked Servers to accomplish this.
You start off by issuing a command to set up the linked server:
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver
@server = N'Server2EnteredTheGame',
@srvproduct=N'SQL Server' ;
GO
And the set things up to use the domain account of the local server:
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname = N'Server2EnteredTheGame',
@locallogin = NULL ,
@useself = N'True' ;
GO
You can then issue queries against the linked server:
SELECT name FROM [Server2EnteredTheGame].MyDatabase.MySchema.MyTable;
GO
However, couldn't you just add a second datasource to the report, and go at it that way?

SchmitzIT
- 9,227
- 9
- 65
- 92