DELIMITER $$

USE `spidd`$$

DROP PROCEDURE `Import_bareme_detail`;

CREATE PROCEDURE `Import_bareme_detail`(var_line NVARCHAR(200))
BEGIN
	
	DECLARE id_details varchar(15);
	DECLARE dbar_nb_place INT;
	DECLARE dbar_nb_point INT;
	DECLARE bar_id BIGINT;
	
	SET id_details = RTRIM(SUBSTRING(var_line, 1, 15))  ;
	SET dbar_nb_place = RTRIM(SUBSTRING(var_line, 16, 8)) ;
	SET dbar_nb_point = RTRIM(SUBSTRING(var_line, 24, 8)) ;
	SET bar_id = RTRIM(SUBSTRING(var_line, 32, 15)) ;

	INSERT INTO BAREME_DETAIL (DBAR_ID_DETAILS, DBAR_NB_PLACE, DBAR_NB_POINT, BAR_ID)
	VALUES (id_details, dbar_nb_place, dbar_nb_point, bar_id)
	ON DUPLICATE KEY UPDATE DBAR_NB_PLACE = VALUES(DBAR_NB_PLACE), DBAR_NB_POINT = VALUES(DBAR_NB_POINT), BAR_ID = VALUES(BAR_ID), BL_MAJ = 1;


END$$

DELIMITER ;