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
 SQL Server Development (2000)
 Sample For StoreProcedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-10 : 09:53:18
Braja writes "Now i want to write a store procedure for pending order. Now i am developing a web based order monitoring system. I am using four table for order and despatch.
for Order entry i have used Order And Orderdetail table. In Order table Fields are [ Orderid , orderno , orederdt , partyinf ] in detail table fields [orderid , prodid , ordqty ].
in despatch table fields [despid , orderid , despdt] in despatchdetail table fields are [despid , prodid , despqty ]
From this storeprocedure i have to find out pending order qty."

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-11 : 19:06:16
Use LEFT JOIN from orderdetail to the despatch tables.

select 	od.*, isnull(dd.despqty, 0) as despqty, (od.ordqty - isnull(dd.despqty, 0))  as pendingqty
from orderdetail od
left join
( despatch dp inner join despatchdetail dd
on dp.despatchid = dd.despatchid
)
on od.orderid = dp.orderid
and od.prodid = dd.prodid
where od.ordqty <> isnull(dd.despqty, 0)


----------------------------------
'KH'

everything that has a beginning has an end
Go to Top of Page
   

- Advertisement -