Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 SQL Server 6.5 \ SQL Server 7.0
 Data from two different database in a single serve

Author  Topic 

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-01-08 : 06:27:36
Dear All,
How to get the data from two different database that is located in a single server.Each databse tables has the empid as the common field.I want to get the salary from other database table has the salary field

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-08 : 06:39:18
Write join query along with database prefixed table names.

Select t1.salary from 
db1.Emp t1 join db2.Sal t2 on t1.empid = t2.empid


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhuotp
Yak Posting Veteran

78 Posts

Posted - 2007-01-08 : 08:41:25
quote:
Originally posted by harsh_athalye

Write join query along with database prefixed table names.

Select t1.salary from 
db1.Emp t1 join db2.Sal t2 on t1.empid = t2.empid


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



small correction
Select t1.salary from
db1.owner.Emp t1 join db2.owner.Sal t2 on t1.empid = t2.empid[/code]
Owner can be dbo or any other user in sql 2000
in sql 2005 replace Owner with Schema
Madhu

Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-03-06 : 03:24:33
Sorry for the late Reply.
I am getting error message as invalid column name.I am running from Query Analyzer
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-06 : 03:28:27
Which error message?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-06 : 03:33:43
Isn't it but obvious?

If you just copy and pasted my query and ran it, you may get error.
You have to make appropriate changes in the query depending on your table and column names. The query I gave is just to give an idea of what you need to do. (Otherwise post table structure here!)

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -