الخميس، 16 أكتوبر 2008

Tranfer item- store to HQ - Not Exists in the HQ

My first post will solve an important problem that most of the RMS users might face!
This problem posted by MR. Mark Casteel and his problem was:
“I am having issues with employees that added local items to our SO database and we are now unable to transfer these item to another store with HQ due to not having correct HQID.

To solve this problem I wrote the following script which will transfer the new items in the SO DB to the HQ DB and update the new item’s HQID based on the new ID created in the HQ DB:
All you have to do is; run the script: then download the new items add to the other stores using the worksheet Style 260 (Download Items).

The script:

DECLARE
@BinLocation nvarchar(20),
@BuydownPrice money,
@BuydownQuantity float ,
@CommissionAmount money ,
@CommissionMaximum money ,
@CommissionMode int ,
@CommissionPercentProfit real ,
@CommissionPercentSale real ,
@Description nvarchar(30) ,
@FoodStampable bit ,
@HQID int ,
@ItemNotDiscountable bit ,
@LastReceived datetime ,
@LastUpdated datetime ,
@Notes nvarchar(1000) ,
@QuantityCommitted float ,
@SerialNumberCount int ,
@TareWeightPercent float ,
@ID int ,
@ItemLookupCode nvarchar(25) ,
@DepartmentID int ,
@CategoryID int ,
@MessageID int ,
@Price money ,
@PriceA money ,
@PriceB money ,
@PriceC money ,
@SalePrice money ,
@SaleStartDate datetime,
@SaleEndDate datetime,
@QuantityDiscountID int ,
@TaxID int ,
@ItemType smallint ,
@Cost money ,
@Quantity float ,
@ReorderPoint float ,
@RestockLevel float ,
@TareWeight float ,
@SupplierID int ,
@TagAlongItem int ,
@TagAlongQuantity float ,
@ParentItem int ,
@ParentQuantity float ,
@BarcodeFormat smallint,
@PriceLowerBound money ,
@PriceUpperBound money ,
@PictureName nvarchar(50) ,
@LastSold datetime ,
@ExtendedDescription nvarchar(1000) ,
@SubDescription1 nvarchar(30) ,
@SubDescription2 nvarchar(30) ,
@SubDescription3 nvarchar(30) ,
@UnitOfMeasure nvarchar(4) ,
@SubCategoryID int ,
@QuantityEntryNotAllowed bit ,
@PriceMustBeEntered bit ,
@BlockSalesReason nvarchar(30) ,
@BlockSalesAfterDate datetime ,
@Weight float ,
@Taxable bit ,
@DBTimeStamp timestamp,
@BlockSalesBeforeDate datetime ,
@LastCost money ,
@ReplacementCost money ,
@WebItem bit ,
@BlockSalesType int ,
@BlockSalesScheduleID int ,
@SaleType int ,
@SaleScheduleID int ,
@Consignment bit ,
@Inactive bit ,
@LastCounted datetime ,
@DoNotOrder bit ,
@MSRP money ,
@DateCreated datetime ,
@Content nvarchar(1000) ,
@UsuallyShip nvarchar(255),
@TempSupplierID int



DECLARE item_cursor CURSOR FOR
SELECT [BinLocation]
,[BuydownPrice]
,[BuydownQuantity]
,[CommissionAmount]
,[CommissionMaximum]
,[CommissionMode]
,[CommissionPercentProfit]
,[CommissionPercentSale]
,[Description]
,[FoodStampable]
,[HQID]
,[ItemNotDiscountable]
,[LastReceived]
,[LastUpdated]
,[Notes]
,[QuantityCommitted]
,[SerialNumberCount]
,[TareWeightPercent]
,[ItemLookupCode]
,[DepartmentID]
,[CategoryID]
,[MessageID]
,[Price]
,[PriceA]
,[PriceB]
,[PriceC]
,[SalePrice]
,[SaleStartDate]
,[SaleEndDate]
,[QuantityDiscountID]
,[TaxID]
,[ItemType]
,[Cost]
,[Quantity]
,[ReorderPoint]
,[RestockLevel]
,[TareWeight]
,[SupplierID]
,[TagAlongItem]
,[TagAlongQuantity]
,[ParentItem]
,[ParentQuantity]
,[BarcodeFormat]
,[PriceLowerBound]
,[PriceUpperBound]
,[PictureName]
,[LastSold]
,[ExtendedDescription]
,[SubDescription1]
,[SubDescription2]
,[SubDescription3]
,[UnitOfMeasure]
,[SubCategoryID]
,[QuantityEntryNotAllowed]
,[PriceMustBeEntered]
,[BlockSalesReason]
,[BlockSalesAfterDate]
,[Weight]
,[Taxable]
,[BlockSalesBeforeDate]
,[LastCost]
,[ReplacementCost]
,[WebItem]
,[BlockSalesType]
,[BlockSalesScheduleID]
,[SaleType]
,[SaleScheduleID]
,[Consignment]
,[Inactive]
,[LastCounted]
,[DoNotOrder]
,[MSRP]
,[DateCreated]
,[Content]
,[UsuallyShip]
FROM [StoreDB].[dbo].[Item] where [StoreDB].[dbo].[Item].ItemLookupCode not in (select [HQDB].[dbo].[Item].ItemLookupCode from [HQDB].[dbo].[Item])

OPEN item_cursor


FETCH NEXT FROM item_cursor
INTO @BinLocation
,@BuydownPrice
,@BuydownQuantity
,@CommissionAmount
,@CommissionMaximum
,@CommissionMode
,@CommissionPercentProfit
,@CommissionPercentSale
,@Description
,@FoodStampable
,@HQID
,@ItemNotDiscountable
,@LastReceived
,@LastUpdated
,@Notes
,@QuantityCommitted
,@SerialNumberCount
,@TareWeightPercent
,@ItemLookupCode
,@DepartmentID
,@CategoryID
,@MessageID
,@Price
,@PriceA
,@PriceB
,@PriceC
,@SalePrice
,@SaleStartDate
,@SaleEndDate
,@QuantityDiscountID
,@TaxID
,@ItemType
,@Cost
,@Quantity
,@ReorderPoint
,@RestockLevel
,@TareWeight
,@SupplierID
,@TagAlongItem
,@TagAlongQuantity
,@ParentItem
,@ParentQuantity
,@BarcodeFormat
,@PriceLowerBound
,@PriceUpperBound
,@PictureName
,@LastSold
,@ExtendedDescription
,@SubDescription1
,@SubDescription2
,@SubDescription3
,@UnitOfMeasure
,@SubCategoryID
,@QuantityEntryNotAllowed
,@PriceMustBeEntered
,@BlockSalesReason
,@BlockSalesAfterDate
,@Weight
,@Taxable
,@BlockSalesBeforeDate
,@LastCost
,@ReplacementCost
,@WebItem
,@BlockSalesType
,@BlockSalesScheduleID
,@SaleType
,@SaleScheduleID
,@Consignment
,@Inactive
,@LastCounted
,@DoNotOrder
,@MSRP
,@DateCreated
,@Content
,@UsuallyShip

WHILE @@FETCH_STATUS = 0
BEGIN

Select @TempSupplierID = ( select HQDB.dbo.Supplier.ID from HQDB.dbo.Supplier where HQDB.dbo.Supplier.SupplierName = (select StoreDB.dbo.Supplier.SupplierName from StoreDB.dbo.Supplier where StoreDB.dbo.Supplier.ID = @SupplierID))


INSERT INTO [HQDB].[dbo].[Item]
([BinLocation]
,[BuydownPrice]
,[BuydownQuantity]
,[CommissionAmount]
,[CommissionMaximum]
,[CommissionMode]
,[CommissionPercentProfit]
,[CommissionPercentSale]
,[Description]
,[FoodStampable]
,[HQID]
,[ItemNotDiscountable]
,[LastReceived]
,[LastUpdated]
,[Notes]
,[QuantityCommitted]
,[SerialNumberCount]
,[TareWeightPercent]
,[ItemLookupCode]
,[DepartmentID]
,[CategoryID]
,[MessageID]
,[Price]
,[PriceA]
,[PriceB]
,[PriceC]
,[SalePrice]
,[SaleStartDate]
,[SaleEndDate]
,[QuantityDiscountID]
,[TaxID]
,[ItemType]
,[Cost]
,[Quantity]
,[ReorderPoint]
,[RestockLevel]
,[TareWeight]
,[SupplierID]
,[TagAlongItem]
,[TagAlongQuantity]
,[ParentItem]
,[ParentQuantity]
,[BarcodeFormat]
,[PriceLowerBound]
,[PriceUpperBound]
,[PictureName]
,[LastSold]
,[ExtendedDescription]
,[SubDescription1]
,[SubDescription2]
,[SubDescription3]
,[UnitOfMeasure]
,[SubCategoryID]
,[QuantityEntryNotAllowed]
,[PriceMustBeEntered]
,[BlockSalesReason]
,[BlockSalesAfterDate]
,[Weight]
,[Taxable]
,[BlockSalesBeforeDate]
,[LastCost]
,[ReplacementCost]
,[WebItem]
,[BlockSalesType]
,[BlockSalesScheduleID]
,[SaleType]
,[SaleScheduleID]
,[Consignment]
,[Inactive]
,[LastCounted]
,[DoNotOrder]
,[MSRP]
,[DateCreated]
,[Content]
,[UsuallyShip])
VALUES
@BinLocation
,@BuydownPrice
,@BuydownQuantity
,@CommissionAmount
,@CommissionMaximum
,@CommissionMode
,@CommissionPercentProfit
,@CommissionPercentSale
,@Description
,@FoodStampable
,@HQID
,@ItemNotDiscountable
,@LastReceived
,@LastUpdated
,@Notes
,@QuantityCommitted
,@SerialNumberCount
,@TareWeightPercent
,@ItemLookupCode
,@DepartmentID
,@CategoryID
,@MessageID
,@Price
,@PriceA
,@PriceB
,@PriceC
,@SalePrice
,@SaleStartDate
,@SaleEndDate
,@QuantityDiscountID
,@TaxID
,@ItemType
,@Cost
,@Quantity
,@ReorderPoint
,@RestockLevel
,@TareWeight
,@TempSupplierID
,@TagAlongItem
,@TagAlongQuantity
,@ParentItem
,@ParentQuantity
,@BarcodeFormat
,@PriceLowerBound
,@PriceUpperBound
,@PictureName
,@LastSold
,@ExtendedDescription
,@SubDescription1
,@SubDescription2
,@SubDescription3
,@UnitOfMeasure
,@SubCategoryID
,@QuantityEntryNotAllowed
,@PriceMustBeEntered
,@BlockSalesReason
,@BlockSalesAfterDate
,@Weight
,@Taxable
,@BlockSalesBeforeDate
,@LastCost
,@ReplacementCost
,@WebItem
,@BlockSalesType
,@BlockSalesScheduleID
,@SaleType
,@SaleScheduleID
,@Consignment
,@Inactive
,@LastCounted
,@DoNotOrder
,@MSRP
,@DateCreated
,@Content
,@UsuallyShip)


Update StoreDB.dbo.Item Set HQID = (Select ID from HQDB.dbo.Item where ItemLookupCode = @ItemLookupCode) where StoreDB.dbo.Item.ItemLookupCode = @ItemLookupCode


FETCH NEXT FROM item_cursor INTO @BinLocation
,@BuydownPrice
,@BuydownQuantity
,@CommissionAmount
,@CommissionMaximum
,@CommissionMode
,@CommissionPercentProfit
,@CommissionPercentSale
,@Description
,@FoodStampable
,@HQID
,@ItemNotDiscountable
,@LastReceived
,@LastUpdated
,@Notes
,@QuantityCommitted
,@SerialNumberCount
,@TareWeightPercent
,@ItemLookupCode
,@DepartmentID
,@CategoryID
,@MessageID
,@Price
,@PriceA
,@PriceB
,@PriceC
,@SalePrice
,@SaleStartDate
,@SaleEndDate
,@QuantityDiscountID
,@TaxID
,@ItemType
,@Cost
,@Quantity
,@ReorderPoint
,@RestockLevel
,@TareWeight
,@SupplierID
,@TagAlongItem
,@TagAlongQuantity
,@ParentItem
,@ParentQuantity
,@BarcodeFormat
,@PriceLowerBound
,@PriceUpperBound
,@PictureName
,@LastSold
,@ExtendedDescription
,@SubDescription1
,@SubDescription2
,@SubDescription3
,@UnitOfMeasure
,@SubCategoryID
,@QuantityEntryNotAllowed
,@PriceMustBeEntered
,@BlockSalesReason
,@BlockSalesAfterDate
,@Weight
,@Taxable
,@BlockSalesBeforeDate
,@LastCost
,@ReplacementCost
,@WebItem
,@BlockSalesType
,@BlockSalesScheduleID
,@SaleType
,@SaleScheduleID
,@Consignment
,@Inactive
,@LastCounted
,@DoNotOrder
,@MSRP
,@DateCreated
,@Content
,@UsuallyShip

END

CLOSE item_cursor
DEALLOCATE item_cursor

ليست هناك تعليقات: