Monday, March 26, 2012

Need syntax help in join from two DB

Hi

I have two databases on my server, I need a simple query with one join between one table from each database.
I looked in the help of FROM clause and found the Argument "table_source" where it explains this :
"If the table or view exists in another database on the same computer running Microsoft SQL Server, use a fully qualified name in the form database.owner.object_name".

Can someone please help me fill the variants ??
My DB name is "Forum" the owner is "DBRND\Administrator" and the table name is "TblUsers", so I tried to write in the FROM clause :
"FROM Forum.DBRND\Administrator.TblUsers" but it doesn't work... so anyone have any idea how should it be ?

Thanks,

Inon.select a.col, b.col
from db1..table1 a, db2..table2 b
where a.colX = b.colX
etc...|||Your object owner is DBRND\Administrator?

Look at the list of tables in Enterprise Manager. They are most likely owned by dbo:

select * FROM Forum.dbo.TblUsers

AND PLEASE DON'T LINK TABLES IN THE WHERE CLAUSE! (My pet peeve...)

select a.col, b.col
from db1..table1 a
inner join db2..table2 b on a.colX = b.colX

Code like a pro!|||(My pet peeve...)Oh, oh! I had a peeve once! Everybody kept feeding it, until it almost ate me.

I've gotten a wee bit jaded since then, but I suspect that you'd noticed.

-PatP|||Thanks A LOT!

Sorry about pushing this thread up... :)

BTW, is joining from two databases on the same server is recommended ? Because I have an option to combine the two databases, so how bad is it (if at all) to leave it like it is.

Inon.

No comments:

Post a Comment