I have scenario like, I need to add my join in conditional
e.g. When value is 1 then inner join to table a and if value 2 then inner join to table
below is my sample query and I am getting error Incorrect syntax near the keyword 'inner'
DECLARE @i INT=1
select name from emp
if(@i=1)
begin
inner join a on a.ID=emp.ID
end
else if(@i=1)
begin
inner join b on b.ID=emp.ID
end
where emp.ID=2
Thanks