Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 list column insert

Author  Topic 

alecwh22
Starting Member

15 Posts

Posted - 2011-12-02 : 08:36:05
I have a statement

select top 1 tabl1_col1
from table1

/*result
col1
----------------------------
('thing1','thing2','thing3')

*/

and I want to do

select col1_table2
from table2
where col2_table2 in (select top 1 tabl1_col1 from table1)

but its doesn't work :'(

my plan to solve it is to take the list and put it into a column in
a temp table but can't think how to do it. can anyone think of a way
or an alternative?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-02 : 08:38:15
take a look here http://www.sommarskog.se/arrays-in-sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-02 : 09:25:52
shouldnt it be


select col1_table2
from table2
where ',' + (select top 1 tabl1_col1 from table1) + ',' like '%,' + col2_table2 + ',%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-12-02 : 09:34:51
I'm guessing that the quote delimitters are there for a reason

where (select top 1 replace(replace(tabl1_col1,'(',','''),'(',''',') from table1) like '%,''' + col2_table2 + ''',%'


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -