I have a SQL query where in I have to fetch an additional param from a different table, only if a value is present in the primary table. I have tried using the if else clause, but it never works.
The SQL looks like this:
SELECT
hist.I_PAYT_REF AS PAY_REF,
hist.C_USERID AS USER_ID,
IF(@hist.I_PAYT_REF IS NULL)
BEGIN
SELECT
PAYT.I_PAYT_REQ_SUM AS PAYMENT_FILE_ID
Join
SP.TSP_CP_PAYT_RQ_DTL PAYT ON PAYT.I_PAYT_REF = hist.I_PAYT_REF
END
FROM
sp.TSP_CP_HIST hist
WHERE
hist.C_HIST_TYPE ='V'
All I want to do is fetch a a new parameter if the hist.I_PAYT_REF is not null. Any help will be greatly appreciated.
Thanks, Yeshwanth