IF EXISTS (SELECT
						 *
					 FROM
						 sys.objects
					 WHERE
						object_id = OBJECT_ID('[dbo].[P_EST_WMS_ENT_RET_PEND_CRIAR_PENDENCIA]') AND
						type IN ( 'P', 'PC' ))
	DROP PROCEDURE [dbo].[P_EST_WMS_ENT_RET_PEND_CRIAR_PENDENCIA]
GO
--EXEC P_EST_WMS_ENT_RET_PEND_CRIAR_PENDENCIA 26142
CREATE PROCEDURE P_EST_WMS_ENT_RET_PEND_CRIAR_PENDENCIA @CD_PED_WMS INT
AS

DELETE FROM EST_WMS_ENT_RET_PEND WHERE CD_PED_WMS = @CD_PED_WMS

INSERT INTO EST_WMS_ENT_RET_PEND
(CD_PED_WMS,
CD_IT,
DT_CONSD)
select
	CD_PED_WMS,
	CD_IT,
	GETDATE() 
from
	EST_WMS_ENT_RET
where
	CD_PED_WMS = @CD_PED_WMS