Well,
i receive an Internal SQL Server Error when i try to
execute this query under SQL Server 7.0 sp4:
Code:
Select ordr.Articolo
, Min(ordr.DtaPrevCon) as 'ConsegnaPrev'
From
mxw.OFoRighe ordr inner join
mtws.vw_Articoli_Magazzino am on am.Articolo = ordr.Articolo and am.Deposito = 'SEDE'
where
ordr.RigaAnn = 0
and ordr.GiaConsegn = 0
and ordr.TipoRiga = 3538947
and ordr.Quantita > 0
and ((Select
isnull(sum(ordr2.Quantita),0)+ordr.Quantita
From mxw.OFoRighe ordr2
Where
ordr2.RigaAnn = 0
and ordr2.GiaConsegn = 0
and ordr2.TipoRiga = 3538947
and ordr2.Quantita > 0
and ordr2.articolo = ordr.articolo
and ordr2.idOrdFor < ordr.idOrdFor) + isnull
(am.InMagazzino,0)) > 0
Group By ordr.Articolo
Order By ordr.Articolo
This query normally run under sql server 2000 sp2.
I have read some ms articles but i did found any solution
to my problem. If i don't use any aggregate function and
grouping records by first and second field, this error
continue to be raised to me.
I think there is a bug in the aggregate function (SUM)
placed in the nested select query in the where clause
which sum the quantity in the old product orders rows that
the actual row.
Practically,
i had join a table with a view:
[OFoRighe] (orders row table) which contains these columns:
Order_id, Articolo (product_id and SKU), Quantita
(Quantity), DtaPrevCon (DeliveryDate)
[vw_Articoli_Magazzino] (this view select the availability
of products in warehouse)
Articolo (product_id and SKU), Deposito (warehouse
location) , InMagazzino (actual available quantity,
considering account orders. Therefore this value could be
negative.)
My problem? I need to know which is the first delivery
date per product (if exists) considering all supplier
orders and get the first date of the order that contains
such quantity that summed to my availability is > 0.
Excuse for my english, and thank to who read since here.
JP