Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2008, 03:19 PM
Authorized User
 
Join Date: Mar 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting data from link tables

Just a quick question regarding SQL to get data from tables which are linked together. I'll try to do my best in describing the sitiuation to make it clear.

Right, I want to get data from 2 fields in a table called GPS (lon & lat). Each lon & lat value is assigned to one ship (can be null). The following tables are involved in this problem:

Ordersonship (ShipID, OrderID)
OrderID(OrderID, CustomerID, Date, ...)
ShipID(ShipID, Name, Docked...)
GPS(ShipID, lat, lon, date)

All tables are linked together. On my web form I have a drop down box which makes a OrderID selectable in the Ordersonship table (since not all orders have been assigned). I need to write a SQL command to get the lat & lon from the GPS table. First of all is this possible? And is the following SQL commands going the right way about it?

SELECT lat
FROM GPS g, ShipID s, Ordersonship o
Where o.OrderID = @SelectedOrderID
AND s.ShipID = g.ShipID

comm.Parameters.Add("@SelectedOrderID", System.Data.SqlDbType.Int);
comm.Parameters["@SelectedOrderID"].Value =
Convert.ToInt32(SelectedOrderDropDownBox.SelectedV alue);

SELECT lon
FROM GPS g, ShipID s, Ordersonship o
Where o.OrderID = @SelectedOrderID
AND s.ShipID = g.ShipID

comm.Parameters.Add("@SelectedOrderID", System.Data.SqlDbType.Int);
comm.Parameters["@SelectedOrderID"].Value =
Convert.ToInt32(SelectedOrderDropDownBox.SelectedV alue);


Would there be a better way of writing this, instead of the 2 commands? I am I even looking in the right direction?

Many thanks for any help, I hope I have explained it well enough :S

Regards,

Peter






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to link new tables using code to MSAccess Nordiers Access VBA 2 January 10th, 2008 11:35 PM
link 2 tables only for application, not for databa W052107 ASP.NET 2.0 Professional 2 May 29th, 2007 07:41 AM
Link FoxPro tables through OLEDB catudalg Access 2 May 8th, 2007 08:16 AM
Link tables from two different SQL Databases Folorunso Agbeja SQL Server 2000 1 October 19th, 2006 08:23 AM
Link Tables thru VBA Rchanga Access 1 November 20th, 2004 11:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.