Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frens


I ve a query which returns a set of IDs ex: str abc= select id from employee where salary>1000


I have to pass these values(ie, abc) into the other query ( ex: select * from [Table] where id IN (1.2,3,4 ) ....

How to get those ids as a comma separated ids


Please suggest me guys

thanks
darshan
Posted

I found this answer to a similar question: sql-how-to-concatenate-results[^]
SQL
declare @result varchar(500)
set @result = ''
select @result = @result + ModuleValue + ', ' 
from TableX where ModuleId = @ModuleId
 
Share this answer
 
According to me kindly try below Sql string:

Select * from [Table] where id IN (1.2,3,4 ) and salary>1000
 
Share this answer
 
v2
easy... do not need to do more code...
just write directly your query as subquery inside "in" clause :)
SQL
select * from [Table] 
where id IN (select id from employee where salary>1000) 

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900