{$page}

This series of SQL queries will reset all warehouse records back to the default. In essence, it reassigns all past and current warehouses records to the default (ID=10) warehouse.

High. Data is modified in this query. Do not run this except under the direction of a Cyrious Technical Support staff member. Doing otherwise may result in lost or contaminated data. All data modifications done through direct SQL are permanent and non-reversable.

This query assumes there is only one inventory record for each warehouse in the database. We have encountered a number of cases where (probably due to some historical issue) certain parts may have multiple warehouse entries. This causes the merge process to fail (since it doesn't know which Inventory record is the one to use) and must be resolved first.

To identify any of the problems, run the following SQL. If it finds any results, they must be cleared before the subsequent queries will run successfully. This query checks to make sure you do not have more than 1 warehouse inventory record for ID = 10, if you did then when we attempt to consolidate we would run into errors. If you do have any records show up you must merge the duplicate warehouse summary records into each other.

code_formatsql

select ID, ClassTypeID, ItemName, PartID, WarehouseID, *

from Inventory

where PartID in

(

  select PartID
  from Inventory
  where WarehouseID=10 and ClassTypeID=12200
  group by PartID
  having Count(*) > 1

)

and WarehouseID=10 and ClassTypeID=12200

order by Inventory.ItemName

code

The following SQL can be run to merge all the warehouse entries into the default warehouse. It also sets this warehouse active and all the others inactive. It does not deactivate warehouses, however. If this is desired it should be done manually afterwards under Setup | Accounting Setup | General.

code_formatsql

– this set of queries merges all warehouse items back to the default warehouse (10)

– ————————————————————————————–

– set all warehouses but 10 inactive, and make 10 the default

– ————————————————————————————–

update PricingElement

set IsActive = 0, IsDefault = 0

where classtypeid = 12700 and ID 10

;

update PricingElement

set IsActive = 1, IsDefault = 1

where classtypeid = 12700 and ID = 10

– ————————————————————————————–

– change all the InventoryID fields to use the Inventory for the default warehouse

– ————————————————————————————–

– update the InventoryID for the Transpart

update Transpart

set InventoryID =

  (select ID from Inventory where Transpart.PartID=Inventory.PartID and Inventory.WarehouseID=10 and Inventory.ClassTypeID=12200)

where (PartID is not NULL)

– update the InventoryID for the VendorTransDetail's AttachedOrderInvID

update VendorTransDetail

set AttachedOrderInvID =

  (select ID from Inventory where VendorTransDetail.AttachedOrderPartID=Inventory.PartID and Inventory.WarehouseID=10 and Inventory.ClassTypeID=12200)

where (AttachedOrderPartID is not NULL)

– update the InventoryID for the InventoryLog

update InventoryLog

set InventoryID =

  (select ID from Inventory where InventoryLog.PartID=Inventory.PartID and Inventory.WarehouseID=10 and Inventory.ClassTypeID=12200)

where (PartID is not NULL)

– update the InventoryID for the Ledger

update Ledger

set InventoryID =

  (select ID from Inventory where Ledger.PartID=Inventory.PartID and Inventory.WarehouseID=10 and Inventory.ClassTypeID=12200)

where (PartID is not NULL)

– ————————————————————————————–

– change all the warehouses to use the default

– ————————————————————————————–

– change all orders to use the standard warehouse

update TransHeader

set WarehouseID = 10

where (WarehouseID 10) or (WarehouseID is NULL)

– change order all line items to use the standard warehouse

update TransDetail

set WarehouseID = 10

where (WarehouseID 10) or (WarehouseID is NULL)

– change PO/Bill line items to use the standard warehouse

update VendorTransDetail

set WarehouseID = 10

where (WarehouseID 10) or (WarehouseID is NULL)

– change all order parts to use the standard warehouse

update TransPart

set WarehouseID = 10

where (WarehouseID 10) or (WarehouseID is NULL)

– set all time cards to use the standard warehouse

update PartUsageCard

set WarehouseID = 10

where (WarehouseID 10) or (WarehouseID is NULL)

– set all inventoryLog records to use the standard warehouse

update InventoryLog

set ToWarehouseID = 10

where (ToWarehouseID 10) and (ToWareHouseID is not NULL)

;

update InventoryLog

set FromWarehouseID = 10

where (FromWarehouseID 10) and (FromWareHouseID is not NULL)

– merge all inventory records into the default warehouse

update Inventory

set

  QuantityBilled        = (select sum(QuantityBilled)         from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityReceivedOnly  = (select sum(QuantityReceivedOnly)   from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityOnHand        = (select sum(QuantityOnHand)         from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityReserved      = (select sum(QuantityReserved)       from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityAvailable     = (select sum(QuantityAvailable)      from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityOnOrder       = (select sum(QuantityOnOrder)        from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityExpected      = (select sum(QuantityExpected)       from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID)

where WarehouseID = 10 and ClassTypeID=12200

;

update Inventory

set

  QuantityBilled        = 0,
  QuantityReceivedOnly  = 0,
  QuantityOnHand        = 0,
  QuantityReserved      = 0,
  QuantityAvailable     = 0,
  QuantityOnOrder       = 0,
  QuantityExpected      = 0

where 1) and ClassTypeID=12200

– merge the summary inventory record into the default warehouse

update Inventory

set

  QuantityBilled        = (select sum(QuantityBilled)         from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityReceivedOnly  = (select sum(QuantityReceivedOnly)   from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityOnHand        = (select sum(QuantityOnHand)         from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityReserved      = (select sum(QuantityReserved)       from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityAvailable     = (select sum(QuantityAvailable)      from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityOnOrder       = (select sum(QuantityOnOrder)        from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID),
  QuantityExpected      = (select sum(QuantityExpected)       from Inventory I2 where I2.ClassTypeID=12200 and I2.PartID = Inventory.PartID)

where ClassTypeID=12201

;

– update GL

update Ledger

set WarehouseID = 10

where (WarehouseID 10) and (WarehouseID is not NULL)

code

After the Warehouse history has all been reassigned, the only remnants of the non-default warehouse are in the PricingElement and the Inventory Record. These can then be deleted, but only AFTER the above queries have successfully run.

WARNING Do NOT run this query unless all traces of non-default warehouses have been removed using the previous SQLs or you will experience load failures in your data.

code_formatsql

– 1. delete the unused warehouses

delete

from PricingElement

where classtypeid = 12700 AND ID 10

;

– 2. delete the unused Inventory records

DELETE FROM Inventory

WHERE WarehouseID 10 and classtypeid in (12200,12202)

;

– 3. delete division summary inventory records

DELETE FROM Inventory

where DivisionID 10 and ClassTypeID = 12201

;

– 4. Delete all divisions except default 10.

Update Employee

Set GroupID = 10

Where GroupID in (select ID from EmployeeGroup Where IsDivision = 1 and ID > 10)

;

Update TransHeader

Set ShipFromDivisionID = 10

Where ShipFromDivisionID 10

;

Update TransHeader

Set DivisionID = 10

Where DivisionID 10

;

Update Ledger

SET DivisionID = 10

Where DivisionID 10

;

update Journal

set DivisionID = 10

where DivisionID 10

;

Update Account

SET DivisionID = 10

Where DivisionID 10

;

Delete from EmployeeGroup

Where IsDivision = 1 and ID > 10

;

code

This query will show the total number of division summary, warehouse summary, and inventory records for each part.If you see any number > 1 in any rows then that is bad.

code_formatsql

select

ID

, ItemName

, (select COUNT(*) from Inventory where PartID = part.ID and inventory.ClassTypeID = 12201) as DivisionSummary

, (select COUNT(*) from Inventory where PartID = part.ID and inventory.ClassTypeID = 12202) as WarehouseSummary

, (select COUNT(*) from Inventory where PartID = part.ID and inventory.ClassTypeID = 12200) as InventoryRecord

from Part

where ID > 0 and PartType = 0 and TrackInventory = 1

code

  • Entered : 10/2010
  • Version : 4.5+

1)
WarehouseID 10) or (WarehouseID = NULL
You could leave a comment if you were logged in.