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
 Need a push, please!

Author  Topic 

Gervahlt
Starting Member

3 Posts

Posted - 2010-01-11 : 02:33:51
Okay, my statement is quite a bit more complicated that this, but I'm going to focus on the piece that's kicking me in the stomach right now. I need some way to pull fields from a table where a text column contains any of a list of items in another table.

So, if the below would work (which it doesn't), it would be ideal:

Select a.column1, a.column2
From Table1 a
Where a.column2 LIKE IN('%'+(Select b.column1 From Table2 b)+'%')

Thanks in advance for any help offered!

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-01-11 : 03:34:37
Do you have any relation between Table1 and Table2?

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2010-01-11 : 03:39:41
Hi

Try this

SELECT C.COLUMN1, C.COLUMN2
FROM TABLE1 C
WHERE EXISTS (SELECT *
FROM TABLE2 N
WHERE C.COLUMN2 LIKE N.COLUMN1 + '%')


-------------------------
[R][A][J]

Go to Top of Page

Gervahlt
Starting Member

3 Posts

Posted - 2010-01-11 : 03:40:14
Not really. In this case, the text field contains a listing of course titles that, unfortunately weren't uniform in creation, so they don't conform to a particular format. The criteria field consists of a list of required courses.

The only relation is that, for the records I'm looking for, somewhere within the course title will be the text from the criteria...but it might be anywhere in the title. Right now that list is fairly small, but I'm trying to future-proof this a bit since I won't always be around and make it so their list of required courses can be added to, or changed, later down the road.
Go to Top of Page

Gervahlt
Starting Member

3 Posts

Posted - 2010-01-11 : 03:54:44
rajdaksha - your solution worked like a charm! Thank you!
Go to Top of Page
   

- Advertisement -