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.
Author |
Topic |
kvdev
Starting Member
2 Posts |
Posted - 2003-12-01 : 00:08:37
|
I am banging my head for a small SQL query in SQLServer.I am using 3 tables to get my requred data.Table1 is the master table containing all the names of engineers.Table1 Looks like this:Engineer:--------------1.EngineerCode2.EngineerName3.EngineerTypeTable2 contains orderdetails- In this table I need 2 fields for having 2 conditions.Table2 looks like this:OrderDetails---------------1.OrderID2.OrderDate3.OrderStatusTable3 contains OrderSubDetailsTable3 looks like this:OrderSubDetails------------------1.OrderID2.OrderSubID3.EngineerCodeNow I want No. of Orders handled by all engineers I wrote a query as belowselect e.EngineerCode,count(distinct (osd.OrderID)) from ((Engineer eleft outer join OrderSubDetails osd on e.EngineerCode = osd.EngineerCode)left outer join OrderDetails od on od.OrderID=osd.OrderID and od.Orderdate='2003%' and od.OrderStatus=3)where e.EngineerType=1 group by e.EngineerTypeIn this query the data displayed is same even if I change Orderdate or OrderStatus. I.e it is not considering the second joinAny help is highly appreciatedThanks in advance |
|
|
|
|