create table #sample
(
Col1 varchar(50),
Col2 varchar(50),
Col3 int,
Col4 int
)
insert into #sample VALUES ('xxxx', 'Cake', 1, 1);
insert into #sample VALUES ('Cake', 'xxxx', 2, 1);
insert into #sample VALUES ('xxxx', 'Cake', 2, 0);
insert into #sample VALUES ('xxxx', 'Cake', 0, 0);
insert into #sample VALUES ('Cake', 'xxxx', 2, 0);
insert into #sample VALUES ('Cake', 'xxxx', 2, 0);
select sum(case
when Col1 = 'Cake' then Col3
when Col2 = 'Cake' then Col4
else 0
end) as [value]
from #sample