Inwentaryzacja porownanie arkusza z stanem

/ Pobranie pozycji arkusza spisowego / select i.itemCode,l.locationcode from item.inventorySheetLine isl inner join wms.item i on i.itemid= isl.itemid inner join wms.location l on isl.locationID = l.locationID where inventorySheetId ='778c74a1-720e-e911-9420-d89d6719e0ca'

/ Sprawdzenie stanów / select i.itemCode itemCode, i.itemName itemName, i.itemUnitID , x.itemSerialNumber serialNumber, sum(x.valueIN - x.valueOUT ) stockValue, sum(x.quantityIN - x.quantityOUT) stockQuantity, --max(x.stockBalanceDate) stockDate, l.locationCode warehouseCode, l.locationID, l_l.locationCode locationCode, l_l.locationName locationName

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
 from wms.stockBalanceDate x
 inner join wms.item i on i.itemID = x.itemID
 inner join wms.location l on l.locationID = x.warehouseID
 LEFT  join wms.location l_l on l_l.locationID = x.locationID
where x.stockBalanceDate <= getdate()
and x.warehouseid = '94121e98-e1a1-49ad-a133-8bf228e11a3d' --magazyn
 group by
        i.itemCode  ,
        i.itemName  ,
        x.itemSerialNumber  ,
        l.locationCode  ,
        l.locationID  ,
        l_l.locationCode ,
        i.itemUnitID,
        l_l.locationName
        having          sum(x.valueIN - x.valueOUT )  <>0 and sum(x.quantityIN -  x.quantityOUT) =0