diff --git a/htdocs/includes/modules/societe/mod_codeclient_monkey.php b/htdocs/includes/modules/societe/mod_codeclient_monkey.php
index f305f9fd5bef61840127d8c44690294309d89c71..12bea62c76cb58a134db3a718fdfed8ee8300546 100644
--- a/htdocs/includes/modules/societe/mod_codeclient_monkey.php
+++ b/htdocs/includes/modules/societe/mod_codeclient_monkey.php
@@ -107,7 +107,7 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode
 
 		// D'abord on recupere la valeur max (reponse immediate car champ indexe)
 		$posindice=8;
-		$sql = "SELECT MAX(SUBSTRING(".$field.",".$posindice.")) as max";
+        $sql = "SELECT MAX(SUBSTRING(".$field." FROM ".$posindice.")) as max";   // This is standard SQL
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe";
 		$sql.= " WHERE ".$field." LIKE '".$prefix."____-%'";