DEV Community

Srujana N
Srujana N

Posted on

need help in sql script

Hi all,

My requirement is as below:
I do have three tables and from each table i am taking one column to get the logic. Below are the two logics as per the requirement.

In t3 there is a column called XYZ, by applying the below two logics, the t3.XYZ column should display the result:

Table names:
t1 has columns ABC and MNC
t2 has columns ABC and MNC
t3 has XYZ

1) The t1 and t2 tables have one column called ABC column. when t1.abc and t2.abc contains the value as "Y,", then i need to Display t3.XYZ column as 'INVALID'
or
2) If the t3.xyz matches t1.mnc or t2.mnc then display t3.xyz else INVALID.

I have written the logic as below but it is not working
case
when t1.abc = 'Y' then 'INVALID'
when t2.abc = 'Y' then 'INVALID'
when t3.xyz = t1.mnc or t3.xyz = t2.mnc then t3.xyz
else 'INVALID'
end

But it is taking else part. In this case i need to get the result as t3.xyz. Please help in this case.

Top comments (0)