Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Some one please help

Author  Topic 

jsweazy
Starting Member

3 Posts

Posted - 2008-10-15 : 01:58:59
Ok so i have to do this:

Write a query that would tell you the name of the customer that placed order 21610, and the name of the REP who represents this customer.

Ok to explain the question the CustomerName is in the Customer table, the Order_Num is in the Order table and the Rep_Name is in the Rep Table. In the Order table there is a CustomerNum that has the customers number, which will get the CustomerName in the Customer table. Also in the Customer table there is a Rep_Num field that will help get the RepName in the Rep table

So pretty much what i need to do is look up the Order_Num in the Orders table and get the corresponding CustomerNum. I need to use the CustomerNum to Select the corresponding CustomerName in the Customer table. And i also need to use the CustomerNum to get its Corresponding Rep_Num from the Customer table. Once i get the Rep_Num i need to use it to get the RepName in the Rep table. I need the query to just output the CustomerName and RepName

See i understand what i need to do but i dont know how to do it.
I have no clue to how to query all these at once and just outputing what i need

If you guys could help me write a query or point me to the functions i need to write it

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-10-15 : 03:54:40
you need to join these table together. start by reading up on INNER JOIN. have a go at it and come back if you need some help with it. once you understand the joins, it will be simple query

Em
Go to Top of Page

jsweazy
Starting Member

3 Posts

Posted - 2008-10-15 : 17:10:46
quote:
Originally posted by elancaster

you need to join these table together. start by reading up on INNER JOIN. have a go at it and come back if you need some help with it. once you understand the joins, it will be simple query

Em



Thanks I Figured it out

Here is what i did:

SELECT Customer.CustomerName, Rep.FirstName, Rep.LastName
FROM Orders
INNER JOIN Customer
ON Orders.Customer_Num=Customer.CustomerNum
INNER JOIN Rep
On Customer.Rep_Num = Rep.Rep_Num
WHERE Orders.Order_Num = 21610
Go to Top of Page

wormz666
Posting Yak Master

110 Posts

Posted - 2008-10-15 : 21:39:28
SELECT Customer.CustomerName, Rep.FirstName, Rep.LastName
FROM Orders
INNER JOIN (Customer INNER JOIN Rep
On Customer.Rep_Num = Rep.Rep_Num) ON Orders.Customer_Num=Customer.CustomerNum
WHERE Orders.Order_Num = 21610
Go to Top of Page

jsweazy
Starting Member

3 Posts

Posted - 2008-10-15 : 22:46:43
quote:
Originally posted by wormz666

SELECT Customer.CustomerName, Rep.FirstName, Rep.LastName
FROM Orders
INNER JOIN (Customer INNER JOIN Rep
On Customer.Rep_Num = Rep.Rep_Num) ON Orders.Customer_Num=Customer.CustomerNum
WHERE Orders.Order_Num = 21610




Is that the best way to type it?
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-10-16 : 02:44:24
no, you did it right your own way

Em
Go to Top of Page
   

- Advertisement -