MySQL Forums
Forum List  »  French

Re: Error Code: 1271. Illegal mix of collations for operation 'concat'
Posted by: Jean Molliné
Date: April 21, 2017 03:08PM

Bonsoir,
le seul point que je vois serait au niveau d'une comparaison entre une chaine et une date. Je modifierais donc de la manière suivante :
SELECT
  CONCAT(
      prefixe,
      annee,
      mois,
      jours,
      LPAD(
          IF(
              CAST(CONCAT(t.lastAnnee,'-',t.lastMois,'-',t.lastJours) AS DATE) <> dateCourante,
              0,
              t.numero + 1
          ),
          4,
          '0'
      )
  ) as nouveau_code
from (
  SELECT
    code,
    MID(code, 1, 1) AS prefixe,
    MID(code, 2, 4) AS lastAnnee,
    MID(code, 6, 2) AS lastMois,
    MID(code, 8, 2) AS lastJours,
    MID(CURRENT_TIMESTAMP, 1, 4) AS annee,
    MID(CURRENT_TIMESTAMP, 6, 2) AS mois,
    MID(CURRENT_TIMESTAMP, 9, 2) AS jours,
    MID(code, 10, 4) AS numero,
    CURRENT_DATE as dateCourante
  FROM demandeur
  ORDER BY code DESC
  LIMIT 1
) as t

À vérifier, je n'ai pas testé.

______________________________________________________________
Une question bien formulée, c'est un problème bien compris : ça représente déjà les 3/4 de la réponse ;)

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.