I am currently in situation that I dont know what to do, and have no idea how to solve problem. The problem is that I have one SELECT statment like
SELECT PaymentType FROM ata WHERE ATAID = $ataId
After that I have IF/ELSE
statment like
if ($paymentType != 2 && $paymentType != 3) {
$sql = "SELECT
SUM(aa.Total) AS total
FROM
ata_articles aa
INNER JOIN
weekly_report wr
ON
wr.id = aa.wrId
WHERE
aa.ProjectId = $projectId
AND
aa.AtaId = $ataId
AND
wr.status = 5";
} else {
$sql = "SELECT
SUM(aa.Total) AS total
FROM
ata_articles aa
INNER JOIN
ata a
ON
a.ATAID = aa.ataId
INNER JOIN
invoices i
ON
i.Id = a.financeId
WHERE
aa.ProjectId = $projectId
AND
aa.AtaId = $ataId
AND
i.Status = 6";
}
As you can see the code is write in PHP but I need to write this in Oracle SQL function. So far what I try
CASE WHEN PaymentType != 2 and paymentType != 3 THEN
SELECT PaymentType FROM ata WHERE ATAID = 1889
OR
SELECT
SUM(aa.Total) AS total
FROM
ata_articles aa
INNER JOIN
weekly_report wr
ON
wr.id = aa.wrId
WHERE
aa.ProjectId = 141
AND
aa.AtaId = 1
AND
wr.status = 5
ELSE
SELECT
SUM(aa.Total) AS total
FROM
ata_articles aa
INNER JOIN
ata a
ON
a.ATAID = aa.ataId
INNER JOIN
invoices i
ON
i.Id = a.financeId
WHERE
aa.ProjectId = 1
AND
aa.AtaId = 1
AND
i.Status = 6
END CASE;
I have try a multiple solution but none of these dosn't work. Can someone guide me and tell me what is the best solution to solve this issue ?