luckydexte
Programmer
Hello All,
I am not an SQL expert by any means and I am getting stuck when trying to select multiple fields from two different tables. I understand why I am not able to do what I want to do but I am not sure how to get around it. Here is the SQL statement I have working so far:
SELECT RFT_PERMIT_TYPE, RFT_PERMIT_NO,
SUM(TOTAL_FEE_CHG) AS TOTAL_FEE_CHG,
SUM(TOTAL_FEE_PD) AS TOTAL_FEE_PD, SUM(TOTAL_FEE_BAL) AS TOTAL_FEE_BAL
FROM
(SELECT A.RFT_PERMIT_TYPE, A.RFT_PERMIT_NO, A.RFT_FEE_TYPE,
(CASE WHEN A.RFT_TRANS_TYPE = '2' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '5' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '7' THEN (A.RFT_TRANS_AMT * -1)
ELSE (A.RFT_TRANS_AMT * 1) END) AS TOTAL_FEE_BAL,
(CASE WHEN A.RFT_TRANS_TYPE = '2' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '0' THEN (A.RFT_TRANS_AMT * 1)
WHEN A.RFT_TRANS_TYPE = '1' THEN (A.RFT_TRANS_AMT * 1)
WHEN A.RFT_TRANS_TYPE = '9' THEN (A.RFT_TRANS_AMT * 1)
ELSE 0 END) AS TOTAL_FEE_CHG,
(CASE WHEN A.RFT_TRANS_TYPE = '6' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '5' THEN (A.RFT_TRANS_AMT * 1)
WHEN A.RFT_TRANS_TYPE = '7' THEN (A.RFT_TRANS_AMT * 1)
ELSE 0 END) AS TOTAL_FEE_PD
From ROW_PERMIT.ROW_PERMIT_IND B Inner Join
ROW_PERMIT.ROW_FEE_TRANSACTION A On B.PERMIT_TYPE = A.RFT_PERMIT_TYPE
And B.PERMIT_NO = A.RFT_PERMIT_NO
Where (A.RFT_DATE > '01-JAN-08'))
GROUP BY RFT_PERMIT_TYPE, RFT_PERMIT_NO
ORDER BY RFT_PERMIT_NO
This gives me a result set that I can use but I also need fields from the table ROW_PERMIT.ROW_PERMIT_IND. Because I am selecting these values using a subselect from the ROW_FEE_TRANSACTION table I cannot access values from the other table. Any ideas?
Thanks in advance,
Brandon
I am not an SQL expert by any means and I am getting stuck when trying to select multiple fields from two different tables. I understand why I am not able to do what I want to do but I am not sure how to get around it. Here is the SQL statement I have working so far:
SELECT RFT_PERMIT_TYPE, RFT_PERMIT_NO,
SUM(TOTAL_FEE_CHG) AS TOTAL_FEE_CHG,
SUM(TOTAL_FEE_PD) AS TOTAL_FEE_PD, SUM(TOTAL_FEE_BAL) AS TOTAL_FEE_BAL
FROM
(SELECT A.RFT_PERMIT_TYPE, A.RFT_PERMIT_NO, A.RFT_FEE_TYPE,
(CASE WHEN A.RFT_TRANS_TYPE = '2' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '5' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '7' THEN (A.RFT_TRANS_AMT * -1)
ELSE (A.RFT_TRANS_AMT * 1) END) AS TOTAL_FEE_BAL,
(CASE WHEN A.RFT_TRANS_TYPE = '2' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '0' THEN (A.RFT_TRANS_AMT * 1)
WHEN A.RFT_TRANS_TYPE = '1' THEN (A.RFT_TRANS_AMT * 1)
WHEN A.RFT_TRANS_TYPE = '9' THEN (A.RFT_TRANS_AMT * 1)
ELSE 0 END) AS TOTAL_FEE_CHG,
(CASE WHEN A.RFT_TRANS_TYPE = '6' THEN (A.RFT_TRANS_AMT * -1)
WHEN A.RFT_TRANS_TYPE = '5' THEN (A.RFT_TRANS_AMT * 1)
WHEN A.RFT_TRANS_TYPE = '7' THEN (A.RFT_TRANS_AMT * 1)
ELSE 0 END) AS TOTAL_FEE_PD
From ROW_PERMIT.ROW_PERMIT_IND B Inner Join
ROW_PERMIT.ROW_FEE_TRANSACTION A On B.PERMIT_TYPE = A.RFT_PERMIT_TYPE
And B.PERMIT_NO = A.RFT_PERMIT_NO
Where (A.RFT_DATE > '01-JAN-08'))
GROUP BY RFT_PERMIT_TYPE, RFT_PERMIT_NO
ORDER BY RFT_PERMIT_NO
This gives me a result set that I can use but I also need fields from the table ROW_PERMIT.ROW_PERMIT_IND. Because I am selecting these values using a subselect from the ROW_FEE_TRANSACTION table I cannot access values from the other table. Any ideas?
Thanks in advance,
Brandon