all groups > sql server mseq > march 2004 >
You're in the

sql server mseq

group:

More help with query



More help with query Newbie
3/10/2004 4:57:36 PM
sql server mseq: Variation on prev post . . .

I have 3 tables

SO
SODet, and
SOQuot

SO is linked to SODet by SalesOrder
SO is linked to SOQuot by Quote

I want to update SOQuot.TotalQty with the result of Sum(SODet.OrderQty)

What would the syntax be for this?

Thanks

Re: More help with query Newbie
3/10/2004 5:00:57 PM
Oops forgot the sum(SODet.OrderQty) need to be limited to records with
LineType = '1'

Thanks
[quoted text, click to view]

Re: More help with query Newbie
3/10/2004 5:26:24 PM
I have the following which works ok but I don't want to have to put a quote
no in.

UPDATE SOQuot
SET TotalQty = (Select sum(OrderQty) FROM SODet
INNER Join SO ON SO.SalesOrder = SODet.SalesOrder
WHERE SO.Quote = '00009219' and SODet.Line = '1')
WHERE SOQuot.QuoteNo = '00009219'

If I change the 2nd where clause to SOQuot.QuoteNo = SO.Quote - I get the
message:

The column prefix 'SorMaster' does not match with a table name or alias name
used in the query.

What am I doing wrong

Thanks
[quoted text, click to view]

Re: More help with query Newbie
3/11/2004 8:00:08 AM
thanks
[quoted text, click to view]

Re: More help with query Vishal Parkar
3/11/2004 9:53:41 AM
Try:

begin transaction
UPDATE SOQuot
SET TotalQty = (Select sum(OrderQty) FROM SODet
where SOQuot.SalesOrder = SODet.SalesOrder
and SODet.Line = '1')

--check the data and commit/rollback accordingly.

--
Vishal Parkar
vgparkar@yahoo.co.in

AddThis Social Bookmark Button