Delimiter //
/**
 * Author:  armen
 * Created: 26 févr. 2020
 * renvoi le code langue de l'entité
 */

drop function if exists CASH_BUSINESS_GET_ENTITIES_LANGUAGE_CODE //

Create Function CASH_BUSINESS_GET_ENTITIES_LANGUAGE_CODE(
		identities int unsigned
	)
	returns char(5)
Begin
	return (
			select
                dfl.DF_LANGUAGES_CODE
            From
                ENTITIES ent
                Inner Join CONTACTS_BUSINESS cb
                    On ent.CONT_BUSINESS_ID_CONT_BUSINESS = cb.ID_CONTACTS_BUSINESS
                Inner Join CONTACTS ct
                    On cb.CONTACTS_ID_CONTACTS = ct.ID_CONTACTS
                Inner Join DF_LANGUAGES dfl
                    On ct.DF_LANGUAGES_ID_DF_LANGUAGE = dfl.ID_DF_LANGUAGES
            Where
                ent.ID_ENTITIES = identities
		)
	;
End //
Delimiter ;