Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 10313

Re: ULTIMO PRECIO DE COMPRA DE UN ARTICULO

$
0
0

Carlos, aqui esta el query, con el ultimo precio, seleccionando el mas alto cuando hay 2 o mas ordenes el mismo dia, saludos !

 

 

 

Select

x.itemcode,

x.itemname,

x.price,

x.docdate

 

 

from (

 

 

Select

a.itemcode,

a.itemname,

b.price,

b.docdate

 

 

from

oitm a inner join  por1 b on a.itemcode = b.itemcode

where

b.docdate = (select max(q.docdate) from por1 q where q.itemcode = a.itemcode) and a.itemcode = '[%0]'

 

 

) x

 

 

where x.price = (select max(z.price) from oitm y inner join  por1 z on y.itemcode = z.itemcode

                          where

                               z.docdate = (select max(r.docdate) from por1 r where r.itemcode = y.itemcode) and y.itemcode = '[%0]')


Viewing all articles
Browse latest Browse all 10313

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>