In my sql script I have this:
insert into @res
select
case
when x = 'tblDoll' then (...)
when x = 'tblCar' then (...)
when x = 'tblRocket' then
if rel_table_id = @old_id
(select x.price from tableInDb x where x.id = rel_table.toy_id)
end
from rel_table
where my_toy_id = @toy_id
@old_id is an input parameter.
But something in the if returns syntax error.
rel_table_id is the id of rel_table. How to put an if condition there?
JOINthe two tables, with more nestedCASEexpression like so: