SELECT *
FROM
(SELECT *,
isnull(
(SELECT sum(amount)
FROM v_open_incoming_ar_detail
WHERE inc_ar_id <> 4817
AND ar_invoice_no = v_payment.[Invoice No.]),0) AS [Have Paid]
FROM
(SELECT ID,
ar_invoice_no AS [Invoice No.],
ar_invoice_date AS [Invoice Date],
due_date AS [Due Date],
po_no AS [Po No.],
po_date AS [PO Date],
grand_total AS [Amount],
tax_pph AS [Tax PPh],
amount AS [Current Paid]
FROM v_open_incoming_ar_detail
WHERE inc_ar_id = 4817 ) v_payment
GROUP BY ID,
[Invoice No.],
ar_invoice_date AS [Invoice Date],
[Due Date],
[PO No.],
[PO Date],)
Advertisement
Answer
You can’t alias in a group by , you have a dangling comma after ,[PO Date] in the group by and you didn’t alias the subquery.
select * from (select *, isnull( (select sum(amount) from v_open_incoming_ar_detail where inc_ar_id <> 4817 and ar_invoice_no = v_payment.[Invoice No.]),0) as [Have Paid] from (select ID,ar_invoice_no as [Invoice No.], ar_invoice_date as [Invoice Date], due_date as [Due Date], po_no as [Po No.],po_date as [PO Date], grand_total as [Amount], tax_pph as [Tax PPh], amount as [Current Paid] from v_open_incoming_ar_detail where inc_ar_id = 4817 ) v_payment group by ID,[Invoice No.],ar_invoice_date, --as [Invoice Date], [Due Date] ,[PO No.] ,[PO Date] --, ) as aliasname