Solved

How do I join two databases when there is a "." in the table name.

Posted on 2009-05-19
8
180 Views
Last Modified: 2012-05-07
I am attempting to join two databases on the same sql server. I am able to access the databases like so for most of the tables:

SELECT s.item1,b.item2 FROM db1.dbo.t1 s join db2.dbo.t1 b on s.id1 = b.uid1

But when i need to access a view from db1 that contains a "." in the name of the actual table I get a sys.servers prompting me to add the server name. Example below:

SELECT s.item1,b.item2 FROM db1.dbo.name.v1 s join db2.dbo.t1 b on s.id1 = b.uid1

Unfortunately I cant change the name of the view "name.v1". Any help would be appreciated.
0
Comment
Question by:sbsnewbie
  • 5
  • 3
8 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24428963
Hope this helps:

SELECT s.item1,b.item2 FROM db1.dbo.[name.v1] s join db2.dbo.t1 b on s.id1 = b.uid1
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24428970
You can either use [name.v1] or "name.v1" to tell Server that it is a single word.
0
 

Author Comment

by:sbsnewbie
ID: 24429031
I have tried both of these methods and I now get "invalid object name 'db1.dbo.name.v1'

If i insert a use db1 at the top of the query it works without the db1.dbo...but this wont work within the view I am trying to create in the db2.

Any thoughts?

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24429112
You can obtain an Invalid object name error in SQL Server due to the following reasons.

* the user you are connecting as does not have SELECT, UPDATE, INSERT, DELETE, EXEC permissions on the object;
* you aren't logging in / connecting as the user you expect;
* you are referencing the object without an owner name prefix (or with the wrong owner name);
* you are connected to the wrong database;
* you are, in fact, spelling the object's name incorrectly.

I suspect that you dont have SELECT permission on that view. Can you confirm whether you have SELECT permission on that view.
0
 

Accepted Solution

by:
sbsnewbie earned 0 total points
ID: 24429128
Yes. When i operate this query everything is returned as expected:

SELECT item1 FROM name.v1

Its only when I attempt to join that table across two databases and I am forced to reference it as:

db1.dbo.name.v1 that it errors out.

Its OK, I just went to the source table of the view 'name.v1' and got the data I needed. The source table does not have a "." in the name of the table so this view was created successfully. Thanks for the feedback, still puzzled as to how I can access this correctly.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24429142
In your First Database db1, issue the below and check whether it works or not.

select * from db1.dbo.name.v1

If that fails, then issue the below

select * from db1.name.v1

If below one works, then from db2 issue the below statement which should work fine

select * from db1.name.v1
0
 

Author Comment

by:sbsnewbie
ID: 24429167
First two queries did not work. I have tried all combinations without success.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24429178
Ok. Now provide error messages for each and every execution:

use db1
go

select * from db1.dbo.name.v1

If that fails, then issue the below

use db1
go

select * from db1.dbo.[name.v1]

If that fails, then issue the below

use db1
go

select * from db1.name.v1

If below one works, then from db2 issue the below statement which should work fine

use db2
go
select * from db1.name.v1
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question