Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

sql server query

What s the query syntax to query a table from another db.  am currently n a db named ClentData where some tables resse but  also want to get to a table n a bd called dctonery(sorry lost a letter on my keyboard)
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Try this
SELECT * FROM DATABASENAME.SCHEMA.TABLENAME

Open in new window

so in your case should be
SELECT * FROM dctonery.dbo.n

Open in new window

The schema dbo is just an assumption because its very common...
Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

I think this is what you meant but it says it cannot find the object name

use clientdata
go

SELECT * FROM dictionery.[dbo].[TblCurrentWords]

Open in new window

Does your account has permissions to use this database...?
User generated image
here is a screenshot of the structure
yes I have the permissions as I created both dbs
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As a workaround because maybe something is not as it seems ....go to DevART and download dbForge SQL Complete, v5.5 Express...after you install this you will have intellisense when you are doing queries and it will show you the proper syntax...
this worked:

so I guess that proves the permissions

--use clientdata
--go

--SELECT * FROM dictionery.[dbo].[TblCurrentWords]

use Dictionary


SELECT * FROM [dbo].[TblCurrentWords]

Open in new window

How about right clicking your Dictionary database and Refresh
EDIT: have you tried to match exactly the case ...i see Dictionary working but...dictionary is lowercase
maybe your server collation is case sensitive...so lowercase <> uppercase
thank you the tool you suggested got me to the correct 'way'

use ClientData

SELECT * FROM Dictionary.dbo.TblCurrentWords
So i guess it was case sensitive issue...
You just got a typo in your select:
SELECT * FROM dictionery.[dbo].[TblCurrentWords]

Should be 'a' instead of 'e'.