I am trying to figure out the right code for the below logic. If there is a certain value in the first column, display the value from the second column for that specific record. Can someone please help? Thanks.
CASE WHEN TableA.Column1 = 'a' THEN 'select TableA.Column2 '
WHEN TableA.Column4 = 'b' THEN 'select TableA.Column5'
ELSE TableA.Column6
END AS [Test]
You were almost there just remove the select
from case statement
. Since all the values are coming from same table no need of select
in case statement just keep column name
it will fetch the corresponding column value.
SELECT CASE
WHEN Column1 = 'a' THEN Column2
WHEN Column4 = 'b' THEN Column5
ELSE Column6
END AS [Test]
FROM tableA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With