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 2005 Forums
 Transact-SQL (2005)
 qry help

Author  Topic 

rum23
Yak Posting Veteran

77 Posts

Posted - 2008-11-09 : 20:03:29
I have 3 tables and the details are as follows

tblemployee
----------
employeeID
RowID

tblOrders
---------
employeeID
orderID


tblOrderDetails
---------------
employeeID
orderID
orderDetailID

Based on the RowID (in tblEmployee), I want to retrieve the employeeID from tblEmployee and then get all the orderID's from tblOrders tables and also get orderDetailID from tblOrderDetails table. How do I write this query? This query should be an updatable query

Thanks much.

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-11-09 : 21:51:37
[code]
Select a.EmployeeID,b.orderID,c.OrderDetailID
from
TblEmployee a
Inner Join
TblOrders b
on a.EmployeeID = b.employeeID
inner join
TBlOrderDetails c
on b.OrderID = c.OrderID
where
a.rowID = 2 --Your row ID
[/code]


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-11-09 : 22:45:26
what are fields(columns) do u want to update, on which condition need to be update dated.

UPDATE <tbls>
SET <Cols>
FROM
TblEmployee a
Inner Join
TblOrders b
on a.EmployeeID = b.employeeID
inner join
TBlOrderDetails c
on b.OrderID = c.OrderID
where = <constion>


"There is only one difference between a dream and an aim. A dream requires soundless sleep to see, whereas an aim requires sleepless efforts to achieve..!!"
Go to Top of Page
   

- Advertisement -