PB : select detail_lot.* , CASE WHEN ref = 0 THEN '2219-01-01' WHEN ref = '0218' THEN '2219-01-01' WHEN ref = '0220' THEN '2219-01-01' WHEN ref = '0223' THEN '2219-01-01' WHEN ref = '0226' THEN '2219-01-01' WHEN ref = '0435' THEN '2219-01-01' WHEN ref = '0227' THEN '2219-01-01' WHEN ref = '0230' THEN '2219-01-01' WHEN ref = '0102' THEN '2219-01-01' WHEN ref = '0231' THEN '2219-01-01' WHEN ref = '0232' THEN '2219-01-01' WHEN ref = '0233' THEN '2219-01-01' WHEN ref = '0234' THEN '2219-01-01' WHEN ref = '0236' THEN '2219-01-01' WHEN ref = '0237' THEN '2219-01-01' WHEN ref = '0466' THEN '2219-01-01' WHEN ref = '0214' THEN '2219-01-01' WHEN ref = '0215' THEN '2219-01-01' WHEN ref = '0216' THEN '2219-01-01' WHEN ref = '0212' THEN '2219-01-01' WHEN ref = '0210' THEN '2219-01-01' WHEN ref = '0209' THEN '2219-01-01' WHEN ref = '0208' THEN '2219-01-01' WHEN ref = '0207' THEN '2219-01-01' WHEN ref = '0204' THEN '2219-01-01' WHEN ref = '0203' THEN '2219-01-01' WHEN ref = '0202' THEN '2219-01-01' WHEN ref = '0201' THEN '2219-01-01' WHEN ref = '0199' THEN '2219-01-01' WHEN ref = '0196' THEN '2219-01-01' WHEN ref = '0195' THEN '2219-01-01' WHEN ref = '0194' THEN '2219-01-01' WHEN ref = '0193' THEN '2219-01-01' WHEN ref = '0192' THEN '2219-01-01' WHEN ref = '0190' THEN '2219-01-01' WHEN ref = '0189' THEN '2219-01-01' WHEN ref = '0186' THEN '2219-01-01' WHEN ref = '0185' THEN '2219-01-01' WHEN ref = '0183' THEN '2219-01-01' WHEN ref = '0181' THEN '2219-01-01' WHEN ref = '0178' THEN '2219-01-01' WHEN ref = '0176' THEN '2219-01-01' WHEN ref = '0173' THEN '2219-01-01' WHEN ref = '0167' THEN '2219-01-01' WHEN ref = '0166' THEN '2219-01-01' WHEN ref = '0156' THEN '2219-01-01' WHEN ref = '0155' THEN '2219-01-01' WHEN ref = '0153' THEN '2219-01-01' WHEN ref = '0152' THEN '2219-01-01' WHEN ref = '0151' THEN '2219-01-01' WHEN ref = '0145' THEN '2219-01-01' WHEN ref = '0144' THEN '2219-01-01' WHEN ref = '0143' THEN '2219-01-01' WHEN ref = '0134' THEN '2219-01-01' WHEN ref = '0133' THEN '2219-01-01' WHEN ref = '0132' THEN '2219-01-01' WHEN ref = '0127' THEN '2219-01-01' WHEN ref = '0121' THEN '2219-01-01' WHEN ref = '0124' THEN '2219-01-01' WHEN ref = '0125' THEN '2219-01-01' WHEN ref = '0120' THEN '2219-01-01' WHEN ref = '0118' THEN '2219-01-01' WHEN ref = '0117' THEN '2219-01-01' WHEN ref = '0115' THEN '2219-01-01' WHEN ref = '0114' THEN '2219-01-01' WHEN ref = '0107' THEN '2219-01-01' WHEN ref = '0113' THEN '2219-01-01' WHEN ref = '0106' THEN '2219-01-01' WHEN ref = '0100' THEN '2219-01-01' WHEN ref = '0098' THEN '2219-01-01' WHEN ref = '0095' THEN '2219-01-01' WHEN ref = '0094' THEN '2219-01-01' WHEN ref = '0092' THEN '2219-01-01' WHEN ref = '0087' THEN '2219-01-01' WHEN ref = '0086' THEN '2219-01-01' WHEN ref = '0440' THEN '2219-01-01' WHEN ref = '0085' THEN '2219-01-01' WHEN ref = '0082' THEN '2219-01-01' WHEN ref = '0079' THEN '2219-01-01' WHEN ref = '0071' THEN '2219-01-01' WHEN ref = '0063' THEN '2219-01-01' WHEN ref = '0062' THEN '2219-01-01' WHEN ref = '0061' THEN '2219-01-01' WHEN ref = '0059' THEN '2219-01-01' WHEN ref = '0057' THEN '2219-01-01' WHEN ref = '0046' THEN '2219-01-01' WHEN ref = '0264' THEN '2219-01-01' WHEN ref = '0044' THEN '2219-01-01' WHEN ref = '0037' THEN '2219-01-01' WHEN ref = '0030' THEN '2219-01-01' WHEN ref = '0028' THEN '2219-01-01' WHEN ref = '0025' THEN '2219-01-01' WHEN ref = '0260' THEN '2219-01-01' WHEN ref = '0022' THEN '2219-01-01' WHEN ref = '0021' THEN '2219-01-01' WHEN ref = '0020' THEN '2219-01-01' WHEN ref = '0019' THEN '2219-01-01' WHEN ref = '0376' THEN '2219-01-01' WHEN ref = '0016' THEN '2219-01-01' WHEN ref = '0007' THEN '2219-01-01' WHEN ref = '0002' THEN '2219-01-01' WHEN ref = '0238' THEN '2219-01-01' WHEN ref = '0239' THEN '2219-01-01' WHEN ref = '0240' THEN '2219-01-01' WHEN ref = '0283' THEN '2219-01-01' WHEN ref = '0241' THEN '2219-01-01' WHEN ref = '0248' THEN '2219-01-01' WHEN ref = '0253' THEN '2219-01-01' WHEN ref = '0164' THEN '2219-01-01' WHEN ref = '0014' THEN '2219-01-01' WHEN ref = '0258' THEN '2219-01-01' WHEN ref = '0083' THEN '2219-01-01' WHEN ref = '0023' THEN '2219-01-01' WHEN ref = '0243' THEN '2219-01-01' WHEN ref = '0139' THEN '2219-01-01' WHEN ref = '0445' THEN '2219-01-01' WHEN ref = '0257' THEN '2219-01-01' WHEN ref = '0250' THEN '2219-01-01' WHEN ref = '0244' THEN '2219-01-01' WHEN ref = '0277' THEN '2219-01-01' WHEN ref = '0188' THEN '2219-01-01' WHEN ref = '0228' THEN '2219-01-01' WHEN ref = '0265' THEN '2219-01-01' WHEN ref = '0504' THEN '2219-01-01' WHEN ref = '0013' THEN '2219-01-01' WHEN ref = '0162' THEN '2219-01-01' WHEN ref = '0262' THEN '2219-01-01' WHEN ref = '0004' THEN '2219-01-01' WHEN ref = '0045' THEN '2219-01-01' WHEN ref = '0441' THEN '2219-01-01' WHEN ref = '0101' THEN '2219-01-01' WHEN ref = '0263' THEN '2219-01-01' WHEN ref = '0256' THEN '2219-01-01' WHEN ref = '0247' THEN '2219-01-01' WHEN ref = '0266' THEN '2219-01-01' WHEN ref = '0242' THEN '2219-01-01' WHEN ref = '0219' THEN '2219-01-01' WHEN ref = '0267' THEN '2219-01-01' WHEN ref = '0249' THEN '2219-01-01' WHEN ref = '0268' THEN '2219-01-01' WHEN ref = '0182' THEN '2219-01-01' WHEN ref = '0432' THEN '2219-01-01' WHEN ref = '0269' THEN '2219-01-01' WHEN ref = '0271' THEN '2219-01-01' WHEN ref = '0272' THEN '2219-01-01' WHEN ref = '0273' THEN '2219-01-01' WHEN ref = '0276' THEN '2219-01-01' WHEN ref = '0274' THEN '2219-01-01' WHEN ref = '0245' THEN '2219-01-01' WHEN ref = '0259' THEN '2219-01-01' WHEN ref = '0252' THEN '2219-01-01' WHEN ref = '0275' THEN '2219-01-01' WHEN ref = '0278' THEN '2219-01-01' WHEN ref = '0279' THEN '2219-01-01' WHEN ref = '0280' THEN '2219-01-01' WHEN ref = '0374' THEN '2219-01-01' WHEN ref = '0281' THEN '2219-01-01' WHEN ref = '0509' THEN '2219-01-01' WHEN ref = '282' THEN '2219-01-01' WHEN ref = '0284' THEN '2219-01-01' WHEN ref = '0285' THEN '2219-01-01' WHEN ref = '0286' THEN '2219-01-01' WHEN ref = '0287' THEN '2219-01-01' WHEN ref = '0288' THEN '2219-01-01' WHEN ref = '0289' THEN '2219-01-01' WHEN ref = '0290' THEN '2219-01-01' WHEN ref = '0315' THEN '2219-01-01' WHEN ref = '0293' THEN '2219-01-01' WHEN ref = '0294' THEN '2219-01-01' WHEN ref = '0296' THEN '2219-01-01' WHEN ref = '0297' THEN '2219-01-01' WHEN ref = '0298' THEN '2219-01-01' WHEN ref = '0291' THEN '2219-01-01' WHEN ref = '0292' THEN '2219-01-01' WHEN ref = '0295' THEN '2219-01-01' WHEN ref = '0300' THEN '2219-01-01' WHEN ref = '0373' THEN '2219-01-01' WHEN ref = '0371' THEN '2219-01-01' WHEN ref = '0299' THEN '2219-01-01' WHEN ref = '0138' THEN '2219-01-01' WHEN ref = '0302' THEN '2219-01-01' WHEN ref = '0301' THEN '2219-01-01' WHEN ref = '0303' THEN '2219-01-01' WHEN ref = '0009' THEN '2219-01-01' WHEN ref = '0304' THEN '2219-01-01' WHEN ref = '0314' THEN '2219-01-01' WHEN ref = '0305' THEN '2219-01-01' WHEN ref = '0306' THEN '2219-01-01' WHEN ref = '0307' THEN '2219-01-01' WHEN ref = '0308' THEN '2219-01-01' WHEN ref = '0321' THEN '2219-01-01' WHEN ref = '0309' THEN '2219-01-01' WHEN ref = '0310' THEN '2219-01-01' WHEN ref = '0326' THEN '2219-01-01' WHEN ref = '0318' THEN '2219-01-01' WHEN ref = '0317' THEN '2219-01-01' WHEN ref = '0316' THEN '2219-01-01' WHEN ref = '0319' THEN '2219-01-01' WHEN ref = '0312' THEN '2219-01-01' WHEN ref = '0313' THEN '2219-01-01' WHEN ref = '0320' THEN '2219-01-01' WHEN ref = '0180' THEN '2219-01-01' WHEN ref = '0322' THEN '2219-01-01' WHEN ref = '0323' THEN '2219-01-01' WHEN ref = '0324' THEN '2219-01-01' WHEN ref = '0325' THEN '2219-01-01' WHEN ref = '0327' THEN '2219-01-01' WHEN ref = '0328' THEN '2219-01-01' WHEN ref = '0329' THEN '2219-01-01' WHEN ref = '0330' THEN '2219-01-01' WHEN ref = '0331' THEN '2219-01-01' WHEN ref = '0332' THEN '2219-01-01' WHEN ref = '0333' THEN '2219-01-01' WHEN ref = '0359' THEN '2219-01-01' WHEN ref = '0334' THEN '2219-01-01' WHEN ref = '0335' THEN '2219-01-01' WHEN ref = '0336' THEN '2219-01-01' WHEN ref = '0337' THEN '2219-01-01' WHEN ref = '0338' THEN '2219-01-01' WHEN ref = '0339' THEN '2219-01-01' WHEN ref = '0340' THEN '2219-01-01' WHEN ref = '0422' THEN '2219-01-01' WHEN ref = '0341' THEN '2219-01-01' WHEN ref = '0342' THEN '2219-01-01' WHEN ref = '0343' THEN '2219-01-01' WHEN ref = '0344' THEN '2219-01-01' WHEN ref = '0345' THEN '2219-01-01' WHEN ref = '0346' THEN '2219-01-01' WHEN ref = '1000' THEN '2219-01-01' WHEN ref = '0347' THEN '2219-01-01' WHEN ref = '0348' THEN '2219-01-01' WHEN ref = '0349' THEN '2219-01-01' WHEN ref = '0350' THEN '2219-01-01' WHEN ref = '0352' THEN '2219-01-01' WHEN ref = '0351' THEN '2219-01-01' WHEN ref = '0353' THEN '2219-01-01' WHEN ref = '0354' THEN '2219-01-01' WHEN ref = '0355' THEN '2219-01-01' WHEN ref = '0356' THEN '2219-01-01' WHEN ref = '0357' THEN '2219-01-01' WHEN ref = '0601' THEN '2219-01-01' WHEN ref = '0360' THEN '2219-01-01' WHEN ref = '0361' THEN '2219-01-01' WHEN ref = '0362' THEN '2219-01-01' WHEN ref = '0363' THEN '2219-01-01' WHEN ref = '0364' THEN '2219-01-01' WHEN ref = '0365' THEN '2219-01-01' WHEN ref = '0472' THEN '2219-01-01' WHEN ref = '0367' THEN '2219-01-01' WHEN ref = '0368' THEN '2219-01-01' WHEN ref = '0369' THEN '2219-01-01' WHEN ref = '0370' THEN '2219-01-01' WHEN ref = '0372' THEN '2219-01-01' WHEN ref = '0375' THEN '2219-01-01' WHEN ref = '0377' THEN '2219-01-01' WHEN ref = '0380' THEN '2219-01-01' WHEN ref = '0382' THEN '2219-01-01' WHEN ref = '0379' THEN '2219-01-01' WHEN ref = '0381' THEN '2219-01-01' WHEN ref = '0378' THEN '2219-01-01' WHEN ref = '0383' THEN '2219-01-01' WHEN ref = '0384' THEN '2219-01-01' WHEN ref = '0385' THEN '2219-01-01' WHEN ref = '0386' THEN '2219-01-01' WHEN ref = '0387' THEN '2219-01-01' WHEN ref = '0388' THEN '2219-01-01' WHEN ref = '0389' THEN '2219-01-01' WHEN ref = '0390' THEN '2219-01-01' WHEN ref = '0391' THEN '2219-01-01' WHEN ref = '0392' THEN '2219-01-01' WHEN ref = '0393' THEN '2219-01-01' WHEN ref = '0394' THEN '2219-01-01' WHEN ref = '0395' THEN '2219-01-01' WHEN ref = '0396' THEN '2219-01-01' WHEN ref = '0397' THEN '2219-01-01' WHEN ref = '0398' THEN '2219-01-01' WHEN ref = '0399' THEN '2219-01-01' WHEN ref = '0400' THEN '2219-01-01' WHEN ref = '0401' THEN '2219-01-01' WHEN ref = '0402' THEN '2219-01-01' WHEN ref = '0403' THEN '2219-01-01' WHEN ref = '0405' THEN '2219-01-01' WHEN ref = '0407' THEN '2219-01-01' WHEN ref = '0408' THEN '2219-01-01' WHEN ref = '0409' THEN '2219-01-01' WHEN ref = '0406' THEN '2219-01-01' WHEN ref = '0410' THEN '2219-01-01' WHEN ref = '0411' THEN '2219-01-01' WHEN ref = '0412' THEN '2219-01-01' WHEN ref = '0404' THEN '2219-01-01' WHEN ref = '0413' THEN '2219-01-01' WHEN ref = '0414' THEN '2219-01-01' WHEN ref = '0415' THEN '2219-01-01' WHEN ref = '0420' THEN '2219-01-01' WHEN ref = '0417' THEN '2219-01-01' WHEN ref = '0416' THEN '2219-01-01' WHEN ref = '0418' THEN '2219-01-01' WHEN ref = '0419' THEN '2219-01-01' WHEN ref = '0421' THEN '2219-01-01' WHEN ref = '0431' THEN '2219-01-01' WHEN ref = '0423' THEN '2219-01-01' WHEN ref = '0424' THEN '2219-01-01' WHEN ref = '0425' THEN '2219-01-01' WHEN ref = '0112' THEN '2219-01-01' WHEN ref = '0426' THEN '2219-01-01' WHEN ref = '0430' THEN '2219-01-01' WHEN ref = '0427' THEN '2219-01-01' WHEN ref = '0428' THEN '2219-01-01' WHEN ref = '0429' THEN '2219-01-01' WHEN ref = '0433' THEN '2219-01-01' WHEN ref = '0434' THEN '2219-01-01' WHEN ref = '0489' THEN '2219-01-01' WHEN ref = '0436' THEN '2219-01-01' WHEN ref = '0437' THEN '2219-01-01' WHEN ref = '0438' THEN '2219-01-01' WHEN ref = '0052' THEN '2219-01-01' WHEN ref = '0439' THEN '2219-01-01' WHEN ref = '0446' THEN '2219-01-01' WHEN ref = '0459' THEN '2219-01-01' WHEN ref = '0477' THEN '2219-01-01' WHEN ref = '0463' THEN '2219-01-01' WHEN ref = '0480' THEN '2219-01-01' WHEN ref = '0443' THEN '2219-01-01' WHEN ref = '0442' THEN '2219-01-01' WHEN ref = '0444' THEN '2219-01-01' WHEN ref = '0447' THEN '2219-01-01' WHEN ref = '0448' THEN '2219-01-01' WHEN ref = '0449' THEN '2219-01-01' WHEN ref = '0450' THEN '2219-01-01' WHEN ref = '0451' THEN '2219-01-01' WHEN ref = '0462' THEN '2219-01-01' WHEN ref = '0452' THEN '2219-01-01' WHEN ref = '0453' THEN '2219-01-01' WHEN ref = '0455' THEN '2219-01-01' WHEN ref = '0456' THEN '2219-01-01' WHEN ref = '0454' THEN '2219-01-01' WHEN ref = '0457' THEN '2219-01-01' WHEN ref = '0458' THEN '2219-01-01' WHEN ref = '0460' THEN '2219-01-01' WHEN ref = '0461' THEN '2219-01-01' WHEN ref = '0464' THEN '2219-01-01' WHEN ref = '0465' THEN '2219-01-01' WHEN ref = '0481' THEN '2219-01-01' WHEN ref = '0467' THEN '2219-01-01' WHEN ref = '0471' THEN '2219-01-01' WHEN ref = '0468' THEN '2219-01-01' WHEN ref = '0470' THEN '2219-01-01' WHEN ref = '0469' THEN '2219-01-01' WHEN ref = '0473' THEN '2219-01-01' WHEN ref = '0474' THEN '2219-01-01' WHEN ref = '0475' THEN '2219-01-01' WHEN ref = '0476' THEN '2219-01-01' WHEN ref = '0478' THEN '2219-01-01' WHEN ref = '0479' THEN '2219-01-01' WHEN ref = '0482' THEN '2219-01-01' WHEN ref = '0483' THEN '2219-01-01' WHEN ref = '0484' THEN '2219-01-01' WHEN ref = '0485' THEN '2219-01-01' WHEN ref = '0486' THEN '2219-01-01' WHEN ref = '0488' THEN '2219-01-01' WHEN ref = '0500' THEN '2219-01-01' WHEN ref = '0490' THEN '2219-01-01' WHEN ref = '0501' THEN '2219-01-01' WHEN ref = '0502' THEN '2219-01-01' WHEN ref = '0200' THEN '2219-01-01' WHEN ref = '0503' THEN '2219-01-01' WHEN ref = '0600' THEN '2219-01-01' WHEN ref = '0506' THEN '2219-01-01' WHEN ref = '0700' THEN '2219-01-01' WHEN ref = '0900' THEN '2219-01-01' WHEN ref = '0508' THEN '2219-01-01' WHEN ref = '0653' THEN '2219-01-01' WHEN ref = '0282' THEN '2219-01-01' WHEN ref = '0605' THEN '2219-01-01' WHEN ref = '0602' THEN '2219-01-01' WHEN ref = '0001' THEN '2219-01-01' WHEN ref = '0603' THEN '2219-01-01' WHEN ref = '0604' THEN '2219-01-01' WHEN ref = '0606' THEN '2219-01-01' WHEN ref = '0810' THEN '2219-01-01' WHEN ref = '0609' THEN '2219-01-01' WHEN ref = '0608' THEN '2219-01-01' WHEN ref = '0638' THEN '2219-01-01' WHEN ref = '0800' THEN '2219-01-01' WHEN ref = '0611' THEN '2219-01-01' WHEN ref = '0610' THEN '2219-01-01' WHEN ref = '0613' THEN '2219-01-01' WHEN ref = '0614' THEN '2219-01-01' WHEN ref = '0003' THEN '2219-01-01' WHEN ref = '0617' THEN '2219-01-01' WHEN ref = '0618' THEN '2219-01-01' WHEN ref = '0619' THEN '2219-01-01' WHEN ref = '0620' THEN '2219-01-01' WHEN ref = '0621' THEN '2219-01-01' WHEN ref = '0622' THEN '2219-01-01' WHEN ref = '0623' THEN '2219-01-01' WHEN ref = '0612' THEN '2219-01-01' WHEN ref = '0607' THEN '2219-01-01' WHEN ref = '0632' THEN '2219-01-01' WHEN ref = '0635' THEN '2219-01-01' WHEN ref = '0636' THEN '2219-01-01' WHEN ref = '0637' THEN '2219-01-01' WHEN ref = '633' THEN '2219-01-01' WHEN ref = '0639' THEN '2219-01-01' WHEN ref = '0640' THEN '2219-01-01' WHEN ref = '0642' THEN '2219-01-01' WHEN ref = '0641' THEN '2219-01-01' WHEN ref = '0634' THEN '2219-01-01' WHEN ref = '0643' THEN '2219-01-01' WHEN ref = '0644' THEN '2219-01-01' WHEN ref = '0645' THEN '2219-01-01' WHEN ref = '646' THEN '2219-01-01' WHEN ref = '647' THEN '2219-01-01' WHEN ref = '0010' THEN '2219-01-01' WHEN ref = '0040' THEN '2219-01-01' WHEN ref = '0035' THEN '2219-01-01' WHEN ref = '0649' THEN '2219-01-01' WHEN ref = '0015' THEN '2219-01-01' WHEN ref = '650' THEN '2219-01-01' WHEN ref = '0651' THEN '2219-01-01' WHEN ref = '0648' THEN '2219-01-01' WHEN ref = '0654' THEN '2219-01-01' WHEN ref = 'Copie_de_0151' THEN '2219-01-01' ELSE '2219-01-01' END dispo_order FROM detail_lot WHERE ref <> '' AND Flag_censure = 1 AND detail_lot.quartier IN ('Carr�� d'Or') ORDER BY date_dispo, ref ASC : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '') ORDER BY date_dispo, ref ASC' at line 1