I have a tableA:
Now, if ID = 2 is present in tableA, I want to fill in col = code of table B. Get the maximum value for all values. otherwise, fill it with "123." Here is what I employed:
if exists (select MAX(value) from #A where id = 2)
set code = (select MAX(value) from #A where id = 2)
set code = 123
There must be some issue with BEGIN;END or IF EXIST;ELSE. In essence, I want to skip the else section of the if choose statement and vice versa. Assuming that the choose statement of the IF=part is:
(select MAX(value) from #A where id = 4)
It should just populate 123, coz ID = 4 do not exist !
Can someone please help me with this?