xcaliber2222
Programmer
Hello,
I've been researching this and it seems there are a few ways to approach this, but I'm not sure of the best way and am not sure how to code for it. So hopefully this makes sense. I am trying to accomplish the following:
select value1, value2 from table1
select value3, value4 from table2 where value4 in ('111', '222', '333')
The "IN" clause in the second query above needs to get its values from the "value2" of the first query. I've looked into a cursor loop (I've been told to always try to avoid this in favor of a set based solution), a while loop with temp or derived tables, and perhaps a user defined function to loop through the values in the first query to return the values into the IN clause in the second query, however, I need to return this all in one resultset. Also, I wasn't sure how to construct the single quotes and commas in the "IN" clause.
Any help would be greatly appreciated.
Thank you,
Alejandro
I've been researching this and it seems there are a few ways to approach this, but I'm not sure of the best way and am not sure how to code for it. So hopefully this makes sense. I am trying to accomplish the following:
select value1, value2 from table1
select value3, value4 from table2 where value4 in ('111', '222', '333')
The "IN" clause in the second query above needs to get its values from the "value2" of the first query. I've looked into a cursor loop (I've been told to always try to avoid this in favor of a set based solution), a while loop with temp or derived tables, and perhaps a user defined function to loop through the values in the first query to return the values into the IN clause in the second query, however, I need to return this all in one resultset. Also, I wasn't sure how to construct the single quotes and commas in the "IN" clause.
Any help would be greatly appreciated.
Thank you,
Alejandro