3

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

3 Answers 3

4

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;
Sign up to request clarification or add additional context in comments.

Comments

1

Why not just join?

SELECT 
   *
FROM employee 
   INNER JOIN Temp_ID ON employee.emp_ID = Temp_ID.ID

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.