IF OBJECT_ID('USR_MAG_ITEM_EXP_RUN_PRC_AFTER', 'P') IS NULL
EXEC ('CREATE PROCEDURE [USR_MAG_ITEM_EXP_RUN_PRC_AFTER] as BEGIN SELECT 1 END;')
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Ray Knapp
-- Create date: 2020-03-31
-- Description: Updates Item table with data needed for export to iPaaS.com
-- =============================================
ALTER PROCEDURE [dbo].[USR_MAG_ITEM_EXP_RUN_PRC_AFTER]

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

--UPDATE Location-Specific pricing fields in IM_ITEM FOR PRODUCTS FOR export to iPaaS
UPDATE I
SET USR_LOC_SPEC_INV_JSON = T.QTY_LOC_JSON
FROM IM_ITEM I JOIN (SELECT SKU, QTY_LOC_JSON FROM USR_MAG_ITEM_EXP_PRC) T
ON T.sku = I.ITEM_NO WHERE T.QTY_LOC_JSON <> I.USR_LOC_SPEC_INV_JSON

END