Reputation: 885
I have two tables, Data and Rate. In the Data table, I have the following info:-
As for Rate table, I hv the following info:-
The final output should be in this format:-
The conditions:-
a. If both Local Currency and Document Current are the same, the ExRate must be equal to 1;
b. If they are not the same, then the ExRate will be based on the Local Currency in the Rate table.
How can I generate the above output?
Upvotes: 0
Views: 67
Reputation: 5148
You could use LEFT JOIN
and CASE
SELECT d.*,
CASE
WHEN d.DocumentCurrency = r.LocalCurrency then 1
ELSE r.ExRate
END AS ExRate
FROM Data d
LEFT JOIN Rate r on d.DocumentCurrency = r.DocumentCurrency
AND d.LocalCurrency = r.LocalCurrency
Upvotes: 1