'' group by DATE_FORMAT(doc_date, '%Y-%m'), customer_id, customer_code, customer_name, ncc_customer_code) so_order inner join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as invoice_amt_total from so_invoice where year(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{year}' and month(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{month}' and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_invoice on so_order.customer_id = so_invoice.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt, 0)) as receipt_amt_total from so_receipt where year(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{year}' and month(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{month}' and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_receipt on so_order.customer_id = so_receipt.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as statement_amt_total from so_statement where year(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{year}' and month(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{month}' and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_statement on so_order.customer_id = so_statement.customer_id ]]> '') group by customer_id, customer_code, customer_name, ncc_customer_code) so_order inner join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as invoice_amt_total from so_invoice where DATE_FORMAT(doc_date, '%Y-%m') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 month), '%Y-%m') and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_invoice on so_order.customer_id = so_invoice.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt, 0)) as receipt_amt_total from so_receipt where DATE_FORMAT(doc_date, '%Y-%m') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 month), '%Y-%m') and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_receipt on so_order.customer_id = so_receipt.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as statement_amt_total from so_statement where DATE_FORMAT(doc_date, '%Y-%m') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 month), '%Y-%m') and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_statement on so_order.customer_id = so_statement.customer_id ]]> update wm_book_general set batch_mark = '@{batch_mark}' where warehouse_id = '@{warehouse_id}' and exists ( select 1 from @{detailTableName} document_detail where document_detail.parent_id = '@{document_id}' and document_detail.product_id = wm_book_general.product_id ) and wm_book_general.order_right_code = '@{order_right_code}' and wm_book_general.stock_type_code = '@{stock_type_code}' 1 ]]> delete from wm_book_detail where batch_mark = '@{batch_mark}' and qty_total = 0; delete from wm_book_general where batch_mark = '@{batch_mark}' and qty_total = 0; IFNull(wm_book_detail.qty_available, 0) ]]>