Delimiter //
/**
 * Author:  armen
 * Created: 27 janv. 2020
 */

drop function if exists CASH_BUSINESS_GET_CONTACT_SIRET //

Create Function CASH_BUSINESS_GET_CONTACT_SIRET(
		contacts_ref varchar(40)
	)
	returns Varchar(40)
Begin
	return (
            Select 
                cb.CONTACTS_BUSINESS_SIRET
            From CONTACTS ctc
                Inner Join CONTACTS_BUSINESS cb
                    on cb.CONTACTS_ID_CONTACTS = ctc.ID_CONTACTS
            Where
                ctc.CONTACTS_REF = contacts_ref
            Limit 1
		)
	;
End //
Delimiter ;
