$sel="select
MagName,
WareCode as ProdID,
WareName as ProdName,
PartnerName as CompName,
DATA_FORMAT(LotDate, "dd,mm,yyyy") as ProdDate,
PriceMC_In,
(PriceMC-PriceMC_In)/(select case when PriceMC_In<>0 then PriceMC_In else -1 end)*100 as Extra,
PriceMC,
Qty
from (select 'Ìàãîçèí ¹".$magn."' as MagName,
w.WareCode,
WareName,
p.PartnerName,
l.LotDate,
(select BuyPrice_wt from refWareLots WITH (NOLOCK) where WareID=l.WareID and LotID=l.LotID) as PriceMC_In,
".$datan.".dbo.pv_get_refWareSPs_SalePrice(getdate(), (select IntRecID from ".$datan.".dbo.refWareSPs WITH (NOLOCK) where WareID=l.WareID and PriceListID=1 and PLAccNodeID=0),
(select AccNodeID from ".$datan.".dbo.refWareSPs WITH (NOLOCK) where WareID=l.WareID and PriceListID=10 and PLAccNodeID=0)) as PriceMC,
(select isnull(sum(Qty),0) from ".$datan.".dbo.movWareRems WITH (NOLOCK) where WareID=l.WareID) as Qty
from ".$datan.".dbo.refWareLots l WITH (NOLOCK)
join ".$datan.".dbo.refPartners p WITH (NOLOCK) on l.PartnerID=p.PartnerID
right join ".$datan.".dbo.refWares w WITH (NOLOCK) on l.WareID=w.WareID
where l.LotID<>0 and l.LotID=(select max(LotID) from ".$datan.".dbo.refWareLots WITH (NOLOCK) where WareID=l.WareID) and w.WareCode=".$_POST['cod']."
group by l.WareID, w.WareCode, l.LotDate, l.LotID, w.WareName, p.PartnerID, p.PartnerName) T";
Вот запрос. выделенным пометил дату.
|