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
 General SQL Server Forums
 New to SQL Server Programming
 I know this is stupid. Can someone please explain

Author  Topic 

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2008-09-23 : 17:31:40
I am trying to link 2 tables from 2 databases in a query.

m2mdata01.dbo.somast
Customizations.dbo.somods

If I'm not allowed to use something like:
m2mdata01.dbo.somast.fsono how would I perform the following statement?

select somods.*, dbo.somast.fcompany from somods
inner join m2mdata01.dbo.somast on dbo.soMods.[fsono] = dbo.somast.fsono


I guess I just don't understand the whole ownership thing.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-09-23 : 17:36:55
you have to reference tables like:
dbname.ownerName.TableName

so
select ...
from dbname1.dbo.TableName1 t1 join dbname2.dbo.TableName2 t2 on t1.id = t2.id




_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-23 : 18:04:34
DavidChel,

You can't reference columns like that. The most you can do with columns is two-parts: ObjectName.ColumnName or AliasName.ColumnName. You can fully qualify tables though as spirit1 has shown.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -