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!

View Created in db1.table? Select out of db2.leases?

Status
Not open for further replies.

craigfw

Technical User
Aug 11, 2004
32
0
0
US
Greetings,

I'm trying to write a view that resides in one db1."table" (that doesn't contain the same table as db2) and selects from db2.Lease table. Both db's are in the same SQL Server. I thought I read somewhere that a view you are executing (selecting) from an application had to have reside in the database you are selecting the data from?

Thanks, Craig
 
You can create a view that selects data from another database.
Code:
use db1
go
create view dbo.lease as
select *
from db2.dbo.lease
go


Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Thanks, Appreciate the information guys.
 
Back again,

I'm trying to write this View and it continues to fail. I honestly don't know what is going wrong. As I mentioned earlier. I'm having to create the View in one db and then query the data to another db. The tables in both db's are different. I'm just trying to get to the second db to return a result.

CREATE VIEW dbo.vInstrumentBalanceDue
AS
SELECT *
FROM LRM_Instrument_Tracking.'any_table_name'
go

SELECT Balance, No.
FROM dbo.LARS-Prod$.lease
WHERE Balance <> 0
 
You need to put the owner from the remote database in the FROM command.
Code:
CREATE VIEW dbo.vInstrumentBalanceDue 
AS
    SELECT *
      FROM LRM_Instrument_Tracking.[red]dbo[/red].any_table_name
go

SELECT Balance, No.
FROM dbo.LARS-Prod$.lease
WHERE Balance <> 0

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top