alter proc  Proc_SaveLuckyDraw (
@flag varchar(2) 
,@user varchar(50)
,@xml NVARCHAR(MAX)	=	NULL 
) as
 SET NOCOUNT ON
 IF @flag='i'

	BEGIN
	BEGIN TRY	
	BEGIN TRAN 
		DECLARE @xmlData XML
		SET @xmlData = CAST(@xml AS XML)
		INSERT INTO dbo.LuckyDrawConfig(LuckyDrawFor,Gift,IsProcessed)
		SELECT
		LuckyDrawFor = XCol.value('(LuckyDrawFor)[1]','varchar(100)'),
		Gift =  XCol.value('(Gift)[1]','varchar(100)'),
		IsProcessed = 0
		FROM  @xmlData.nodes('/ArrayOfLuckydraw/Luckydraw') AS XTbl(XCol) 
  
	COMMIT 
		EXEC proc_errorHandler 0, 'Record save Successfully ', ''
		END TRY
	BEGIN CATCH
	IF @@TRANCOUNT > 0
    ROLLBACK
	EXEC proc_errorHandler 1, 'Failed to save record.', ''
	END CATCH
	RETURN
	END

