So the current query I have takes long time to run. When i run execution plan, it shows: Table Insert (#tempdata), Cost: 99%. I realized i need to add non clustered index to run the query fast. So I have added this line of code but still there is no difference:
create nonclustered index #temp_index
on [dbo].#tempData ([class_room]) include ([class_name],[class_floor],[class_building])
This is the current query I have:
IF OBJECT_ID('tempdb..#tempdata') IS NOT NULL DROP TABLE #tempdata
SELECT [class_room][class_name],[class_floor],[class_building]
INTO #tempdata
FROM class_info x
create nonclustered index #temp_index
on [dbo].#tempData ([class_room]) include ([class_name],[class_floor],[class_building])
;with cte1 as(
SELECT [class_room][class_name],[class_floor],[class_building]
FROM #tempdata
WHERE class_room <> '')
select * from cte1