I have two tables as below and description is given in below
id EmployeeID departmentid department1 department2 department3 1 300 100 IT Finance 2 400 101 IT Sales 3 500 102 Technology Finance 4 600 101 IT HWD
id EmployeeID departmentkeys Departmnetvalues 100 300 1 IT 101 400 1 IT 102 500 2 Finance 103 600 1 IT
department table, i have
departmentkeys column that contains the values
1,1,2,1 and maps to column
department3 in the
Employee table .
I want to fetch record based on matching records from
select * from Employee e inner join department d on e.departmentid=d.id and Case When d.departmentkeys=1 then e.department1 When d.departmentkeys=2 then e.department2 When d.departmentkeys=3 then e.department3 End=d.departmentvalues
I do not want to to use CASE statement because its causing a performance issue. Instead of CASE statement i want to use SQL Dynamic query .