468,512 Members | 1,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

error 1064 have detected on a Case When statement, please help

Hi, I'm just a user and I had this query programmed by a friend and seems to have stop working.

The error message I get says that the error is near the CASE WHEN statement at line 8. Any comments are welcomed and if possible suggestions to correct the error.
Expand|Select|Wrap|Line Numbers
  1. Select vendor,F.airline_code,F.invoice_nmr invoice_vendor,F.booking_nmr,
  2. sum(amount) total_factura  , IF(tipo = 'CH',facturado,pagado) monto_pagado,tipo,
  3. concat(b_month,'-',b_year) periodo_factura,F.fecha_carga,date awb_date,count(*) Reg
  4. from p24l3dbd_costos.PAGOS G
  5. RIGHT  JOIN p24l3dbd_costos.FACTURAS F ON  F.booking_nmr = G.booking_nmr and F.airline_code = G.airline_code 
  6. LEFT JOIN  p24l3dbd_costos.GUIAS_ID I ON  F.booking_nmr = I.booking_nmr and F.airline_code = I.id_ch
  7. group by F.airline_code,F.invoice_nmr,F.booking_nmr,F.fecha_carga
  8. order by F.select *, CASE   
  9. WHEN vendor is null THEN 'Sin Guia' ELSE 'Con Guia' END estado_factura,
  10. CASE  WHEN dif <=-5 or vendor is null THEN 'A Disputar' ELSE 'A Pagar' END pagar
  11. from (Select vendor ,airline_code ,invoice_nmr invoice_vendor,F.booking_nmr,date awb_date,F.ori,F.dest ,accrual_cost provision
  12. ,pagado total_pagado,facturado total_facturado,
  13. IF(G.tipo='CH',(accrual_cost-pagado),(accrual_cost-pagado-sum(amount))) dif,
  14. sum(amount) ultima_factura ,nmr_pago ,weight vendor_chw,booking_chw awb_chw,spotref,
  15. concat(substring(billing_per_begin,1,2),'-',substring(billing_per_begin,9,2)) periodo_guia,
  16. concat(b_month,'-',b_year) periodo_factura,tipo,fecha_carga
  17. from p24l3dbd_costos.GUIAS_ID G
  18. RIGHT  JOIN p24l3dbd_costos.FACTURAS F 
  19. ON  F.booking_nmr = G.booking_nmr and F.airline_code = G.id_ch
  20. group by F.airline_code,F.invoice_nmr,F.booking_nmr,fecha_carga) x
  21. order by vendor, (str_to_date(fecha_carga,'%m/%d/%Y')) DESC, vendor desc
Jul 16 '14 #1
1 1010
Rabbit
12,513 Expert Mod 8TB
Please use code tags when posting code or formatted data.

You're saying this used to run? That can't be, it looks like you have 2 different queries running into each other on line 8.
Jul 16 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Morten Gulbrandsen | last post: by
4 posts views Thread by laurenquantrell | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.