I want to take a join if and only if some condition is true. Ex-
Table Employee
emp_no
emp_name
dept_no
Table Departnemt
dept_no
dept_name
declare @takeJoin BIT
select * from Employee e
if @takeJoin then
inner join Department d on e.dept_no=d.dept_no
if @takeJoin is 1 then only inner join should be taken otherwise all records from Employee should be returned as it is.
Can we do it with writing general if else statement? This is just a sample, actual query is huge so general
If @takeJoin =1
begin
end
else
begin
end
will not be an appropriate solution.
Is something like this possible?