selectd.documentdate,d.documentFullNR,w.locationCodewarehouseCode,l.locationCode,c.commisionFullNR,dl.itemQuantity,dl.itemQuantityLeft,dl.itemPrice,dl.sysItemPrice,dl.itemValue,dl.itemValueLeft,dl.sysItemValue,dl.sysItemValueLeft,d.warehouseID,d.documentID,-- w systemie http://lisicki.platformacrm.pl/sales-met/documentIn/86bb2f0f-50f9-e911-8424-7ed30a52f64fdl.documentLineID,-- id pozycjidl.initialsourcedocumentLineID,-- zrodlowy documentLineID (czyli z ktorej partii pochodzi wydanie)i.itemName,dt.documentCategory--warehouse, warehouseC, warehouseHfromdocument.documentLinedlinnerjoindocument.documentdond.documentID=dl.documentIDinnerjoinwms.locationwond.warehouseID=w.locationID--magazynleftjoinwms.locationlonl.locationID=dl.locationid--lokacjainnerjoinwms.itemiondl.itemID=i.itemIDinnerjoindocument.documenttypedtondt.documentType=d.documentTypeleftjoinwms.commisionLineclondl.commisionLineID=cl.commisionLineIDleftjoinwms.commisionconc.commisionID=cl.commisionIDwheredl.itemID='29994D4D-509A-EA11-80E1-9C8E994DC647'--and dt.baseDocumentType = 'wmm' --typ zrodlowy pz,pzianddl.status>0-- tylko zatwierdzone pozycjeandd.status>0-- tylko zatwierdzone dokumentyandd.documentDate>='2023-11-01'andd.documentDate<='2023-11-30'ORDERBYdocumentDate,dl.signvalue*-1,d.documentNR
Sortowanie
Opcja nr 1:
ORDER BY documentDate , dl.signvalue * -1 ,d.documentNR
Wady - nie posortuje dobrze dokumentow WM- i WM+ w tym samym dniu
Opcja nr 2:
order by d.documentDate ,d.fulltextid (chyba najlepsza opcja na razie ??)
--pierwsza cenaselectitemid,sysItemPricefrom(selectrow_number()OVER(PARTITIONBYi.itemidORDERBYd.documentdateDESC)row,i.itemID,dl.sysItemPricefromdocument.documentdinnerjoindocument.documenttypedtondt.documentType=d.documentTypeinnerjoindocument.documentlinedlond.documentid=dl.documentidinnerjoinwms.itemiondl.itemid=i.itemidwheredl.status>=0andd.status>=0anddt.baseDocumentType='pz'--ex. tylko pz, pziandd.documentDate>=@date)xwhererow=1)pierwszacenaondatasummary.itemID=pierwszacena.itemid