syntax error converting mysql4 to mysql 5

Avatar
  • Answered
I have the following code that I cant workout the syntax error to resolve - can anyone help?

# Novated Driver (Budgeted) with funds
# library_type standard
# library_path /lib/PDF
# library_name performance_nofb

SELECT t3.client_code AS client_code
, t3.name AS client_name
, CONCAT(t4.given_name, ', ', t4.surname) AS driver_name
, t1.contract_id AS contract_id, t1.reg_no AS reg_no
, '->total_budgets_gross_ltd' AS total_budgets_gross_ltd
, t2.total_receipted AS total_receipted_amount_gross_ltd
, '->total_actuals_gross_ltd' AS total_actuals_gross_ltd
, '[formula]=round(K#row_no# L#row_no#, 2)' AS current_balance
, 'Fields to the right required for processing' AS 'comment'
, '[formula]=round(G#row_no# - F#row_no#, 2)' AS total_funds_variance_gross_ltd
, '->total_variance_gross_ltd' AS total_variance_gross_ltd
, t30.supplier_code,t30.no_pmts,t30.amount_gross
, DATE_FORMAT(LAST_DAY(SUBDATE(CURDATE(), INTERVAL 0 MONTH)), '%d/%m/%Y') AS date_filter
, DATE_FORMAT(t1.contract_start, '%d/%m/%Y') AS contract_start
, DATE_FORMAT(t1.contract_end, '%d/%m/%Y') AS contract_end
, IF(t1.suspend_date <> '0000-00-00', DATE_FORMAT(t1.suspend_date, '%d/%m/%Y'), '') AS suspend_date
FROM fm_contracts AS t1, fm_clients AS t3
LEFT JOIN fm_drivers AS t4 ON t4.driver_id = t1.driver_id
LEFT JOIN fm_client_groups AS t6 ON t6.client_group_id = t3.client_group_id
LEFT JOIN (SELECT t1.contract_id, t3.supplier_code, COUNT(t2.payment_period_no) AS no_pmts,SUM(t2.amount_net AND t2.amount_gst) AS amount_gross
FROM fm_contract_payment_structures AS t1
LEFT JOIN fm_contract_payment_schedules AS t2
LEFT JOIN fm_suppliers AS t3
WHERE t1.contract_payment_structure_id = t2.contract_payment_structure_id
AND t1.supplier_id = t3.supplier_id
AND t2.status_flag = 'pending'
AND t1.payment_type = 'finance'
AND t2.payment_date <= CURDATE()
GROUP BY t1.contract_payment_structure_id,t1.contract_id, t3.supplier_code, t3.name, t1.supplier_reference, t1.payment_type)AS t30 ON t1.contract_id = t30.contract_id
# LEFT JOIN fm_suppliers AS t7 ON t7.supplier_id = t1.supplier_id
# LEFT JOIN gb_users AS t11 ON t11.user_id = t3.user_id

# Get receipted_amount
LEFT JOIN
(
SELECT t99.contract_id, SUM(t99.amount) AS total_receipted
FROM (
SELECT t20.contract_id AS contract_id, SUM(t22.amount) AS amount
FROM fm_contracts AS t20, fm_billing AS t21, sl_receipt_item_lines AS t22, sl_receipts AS t23
WHERE t22.billing_id = t21.billing_id AND t23.receipt_id = t22.receipt_id AND t21.status_flag = 'posted' AND t22.status_flag IN ('pending', 'posted')
AND t23.transaction_date <= LAST_DAY(SUBDATE(CURDATE(), INTERVAL 0 MONTH))
AND t21.contract_id = t20.contract_id AND (t20.suspend_date = '0000-00-00' OR t20.suspend_date >= LAST_DAY(SUBDATE(CURDATE(), INTERVAL 0 MONTH)))
AND t20.contract_start <= curdate()
GROUP BY t21.contract_id
UNION ALL
SELECT t30.contract_id AS contract_id, SUM(t31.amount) * -1 AS amount
FROM fm_contracts AS t30, sl_on_account AS t31
INNER JOIN sl_receipts AS t32 ON t32.receipt_id = t31.receipt_id
WHERE t31.table_name = 'fm_contracts' AND t31.status_flag IN ('pending', 'posted')
AND t32.transaction_date <= LAST_DAY(SUBDATE(CURDATE(), INTERVAL 0 MONTH))
AND t31.record_id = t30.contract_id AND (t30.suspend_date = '0000-00-00' OR t30.suspend_date >= LAST_DAY(SUBDATE(CURDATE(), INTERVAL 0 MONTH)))
AND t30.contract_start <= curdate()
GROUP BY t31.record_id
) AS t99
GROUP BY t99.contract_id
) AS t2 ON t2.contract_id = t1.contract_id

WHERE t3.client_id = t1.client_id AND t1.reg_no != 'order'
AND (t1.suspend_date = '0000-00-00' OR t1.suspend_date >= LAST_DAY(SUBDATE(CURDATE(), INTERVAL 1 MONTH)))
AND t1.contract_start <= curdate()
AND t30.supplier_code IS NOT NULL
ORDER BY client_name ASC, contract_id ASC;
Avatar
JacobIMH
Hello,

In order for us to help you troubleshoot your syntax error, please provide us with the exact error that you're getting. MySQL usually states what line this occurred on and with which statement.

Unfortunately just seeing a large SQL query without the associated database would make it a very time consuming process for someone to go through line by line and guess what might be going wrong.

- Jacob