Is the following result what you want:
;with cte as(select
max(CASE WHEN Temp_Column='Temp2' THEN 1 ELSE 0 end) Temp2,
max(CASE WHEN Temp_Column='Temp1' THEN 2 ELSE 0 end) Temp1,
max(CASE WHEN Temp_Column='Temp2' THEN 3 ELSE 0 end) Temp22,
max(CASE WHEN Temp_Column='Temp4' THEN 4 ELSE 0 end) Temp4
FROM Temp_Columns)
select *
from Tracking_Data D
Left join cte c on c.Temp2=D.Project_Id or c.Temp1=D.Project_Id
or c.Temp4=D.Project_Id or c.Temp22=D.Project_Id
If what you want is the value in Temp_Column instead of * in
select * from Tracking_Data
as far as I know, you must use dynamic sql, static sql cannot be achieved.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.