--------- some logic
--------- some logic
where empid=(select empid from #emp where deptid=2)
In this case as i said you can insert it (select empid from #emp where deptid=2) to an temptable so tat this temp table 'll be having the corresponding data only. so where ever required you can join with this temp table and achieve the result.
select empid into #TempEmp from emp where deptid=2
--------- some logic
--------- some logic
from tablename TN join #TempEmp TE TN.empid=TE.empid
Hope this Works......