Delimiter //
/**
 * Author:  armen
 * Created: 27 janv. 2020
 */
drop function if exists CASH_BUSINESS_GET_MAIN_CONTACT_SIRET //

Create Function CASH_BUSINESS_GET_MAIN_CONTACT_SIRET(
		accounts_ref varchar(40)
	)
	returns Varchar(40)
Begin
	return 
            (
                Select 
                    cb.CONTACTS_BUSINESS_SIRET
                From ACCOUNTS acc
                    Inner Join CONTACTS_BUSINESS cb
                        on acc.CONTACTS_ID_CONTACTS = cb.CONTACTS_ID_CONTACTS
                Where
                        acc.ACCOUNTS_REF = accounts_ref
                Limit 1
            )
            
	;
End //
Delimiter ;
