I need to add row values from multiple column values from two tables. I have tried below and facing error. how to achieve this.
Note: I need to use as normal select query in my test script, and not as Stored Procedure or any other formats.
if (
select count(Rate_Index_Value)
from LOAN_PAYMENTS
where Loan_ID = 17781
and Processing_End_Date > '9999')
= 1
select
'From LOAN_PAYMENTS table' as tbName,
Rate_Index_Value as Original_Interest_Rate,
*
from LOAN_PAYMENTS
where Loan_ID = 17781
and Processing_End_Date > '9999'
else
begin
select
'From LOAN table' as tbName,
Rate_Index_Value as Original_Interest_Rate,
*
from LOAN
where Loan_ID = 17781
and Processing_End_Date > '9999'
and Business_End_Date > '9999'
select
'From LOAN_PARTY table' as tbName,
(BrokerDealer_Split + LendingBank_Split) as Original_Interest_Rate,
*
from LOAN_PARTY
where Loan_ID = 17781
and Processing_End_Date > '9999'
and Business_End_Date > '9999'
(
(select
Rate_Index_Value
from LOAN
where Loan_ID = 17781
and Processing_End_Date > '9999'
and Business_End_Date > '9999'
)
+
(
select (BrokerDealer_Split + LendingBank_Split)
from LOAN_PARTY
where Loan_ID = 17781
and Processing_End_Date > '9999'
and Business_End_Date > '9999'
)
) as Original_Interest_Rate
end
go
i am getting error in the combined statement line under else condition.
>[Error] Script lines: 1-8 --------------------------
Incorrect syntax near '+'.
Msg: 102, Level: 15, State: 181
>[Error] Script lines: 1-8 --------------------------
Incorrect syntax near ')'.
Msg: 102, Level: 15, State: 181
Updated with my missing keyword: Actually i missed the 'select' keyword before the open bracket on the combined statement and so i was getting the error. After adding , it worked.
select (
(select
Rate_Index_Value
from LOAN
where Loan_ID = 17781
and Processing_End_Date > '9999'
and Business_End_Date > '9999'
)
+
(
select (BrokerDealer_Split + LendingBank_Split)
from LOAN_PARTY
where Loan_ID = 17781
and Processing_End_Date > '9999'
and Business_End_Date > '9999'
)
) as Original_Interest_Rate