Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Selecting from two database problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Selecting from two database problem

 Post Reply Post Reply
Author
srb01uk View Drop Down
Newbie
Newbie
Avatar

Joined: 19 March 2005
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote srb01uk Quote  Post ReplyReply Direct Link To This Post Topic: Selecting from two database problem
    Posted: 19 March 2005 at 10:00am
I am attemting to select data from three tables, one of the tables lives in a different database on the same server. I have included an example of the select statement, but I think the issue revolves around the database.owner.object_name. It maybe to do with correct sytax but could not find any examples only to compare.
 
I understand that data can be selected from other databases even though the strSQL opens only one database connection? 
 
Does anyone have any suggestions please?
 
Thanks in advance.

ulive.SB.admissions (ulive is database name, SB is username, admissions is table name)

strSQL = "SELECT capd_person.p_forenames, capd_person.p_surname, capd_person.p_dob, apd_student.s_studentreference, capd_student.s_studentstatus, admissions.arrival_status " & _
"FROM capd_person INNER JOIN capd_student ON capd_person.p_id = capd_student.s_id LEFT JOIN ulive.SB.admissions ON capd_student.s_studentreference = admissions.stu_reference " & _
"WHERE admissions.arrival_status = '" & arrival_status & "' "
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 19 March 2005 at 6:09pm

SQL Server uses a dot-delimited nomenclature that extends outward to the database and the server. To specify a column in a table in another database, name the other database:

SELECT CustomerID FROM Common.Customers

To join a table from the Common database to a table in the current (Sales) database, use this same nomenclature:

SELECT * FROM Common.Customers
INNER JOIN Orders
ON Common.Customers.CustomerID = Orders.CustomerID

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.