SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_sys_md_maj_labels]
AS

	/*
	DGE 23/08/2014

	Pour la mise à jour des intitulés des colonnes l1, l2, l3: nous avons ajouté les champs 
	fmt_format_l1, fmt_format_l2, fmt_format_l3. Ce champs ne doivent pas être traités comme les champs fmt_l1, fmt_l2, fmt_l3, c'est à fire
	il ne faut pas initialiser automatiquement les libellés avec les valeurs Label/Libellé.

	En général, on initialise les libellés uniquement si le champ est <<prefix>>_l1 (l2, l3), donc si le caractère _ est présent une seule fois
	dans le nom du champ: len(fld_field_name) - len(replace(fld_field_name, '_', '') = 1

	

	*/

	update md_fields set fld_l1 = 'Label ({0})' where fld_field_name like '%l1' and len(fld_field_name) - len(replace(fld_field_name, '_', '')) = 1
	update md_fields set fld_l1 = 'Label ({0})' where fld_field_name like '%l2' and len(fld_field_name) - len(replace(fld_field_name, '_', '')) = 1
	update md_fields set fld_l1 = 'Label ({0})' where fld_field_name like '%l3' and len(fld_field_name) - len(replace(fld_field_name, '_', '')) = 1

	update md_fields set fld_l2 = 'Libellé ({0})' where fld_field_name like '%l1' and len(fld_field_name) - len(replace(fld_field_name, '_', '')) = 1
	update md_fields set fld_l2 = 'Libellé ({0})' where fld_field_name like '%l2' and len(fld_field_name) - len(replace(fld_field_name, '_', '')) = 1
	update md_fields set fld_l2 = 'Libellé ({0})' where fld_field_name like '%l3' and len(fld_field_name) - len(replace(fld_field_name, '_', '')) = 1

	update md_fields set fld_l1 = 'Freeze', fld_l2 = 'Freeze', fld_l3 = 'Freeze' where fld_field_name like '%freeze'
	update	md_fields 
	set		fld_l1 = 'Date of set up', 
			fld_l2 = 'Date d''effet' 
	where	fld_field_name like '%date_setup'
	and		fld_field_name != 'cl_date_setup'

	update md_fields set fld_l1 = 'rowver', fld_l2 = 'rowver', fld_l3 = 'rowver' where fld_field_name like '%rowver'
	
	--update md_fields set fld_l1 = 'Culture', fld_l2 = 'Culture' where fld_field_name like '%culture_code'
	update md_fields set fld_l1 = 'System field', fld_l2 = 'Champ système' where fld_field_name like '%sys'




GO
