Reputation: 7777
i have an values in temp table like this
ID
1
2
3
but know from employee table i need to select values based from temp table
declare @mStrvalue as varchar(100)
select @mStrvalue =IDS from Temp_ID
select * from employee where employee.emp_ID= @mStrvalue
Right now this staement is giving me only 1 row value actually there is data present for all the ids
is there anything wrong in th e syntax that i am going, pls let me know.
thnkas prince
Upvotes: 3
Views: 95
Reputation: 56769
You will want to join the temp table with the employee table:
select e.*
from employee e
inner join Temp_ID t on e.emp_id = t.ids
This should return only employees whose id's are in the temp table.
Upvotes: 0
Reputation: 181280
Try this:
select * from employee where employee.emp_ID in (select IDS from Temp_ID);
Or you could just join the two tables.
select *
from employee inner join Temp_ID on employee.id = Temp_ID.IDS;
Upvotes: 4
Reputation: 175766
Why not just join?
SELECT
*
FROM employee
INNER JOIN Temp_ID ON employee.emp_ID = Temp_ID.ID
Upvotes: 1