Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I want to use LIKE on a subselect from a temporary table. Something like this:SELECT *FROM myTableWHERE myWord LIKE (SELECT word FROM #myTempTable)only this doesn't work :-)So what should I do?
Crespo
85 Posts
Posted - 2002-08-06 : 05:38:03
As you said in your post, your query does not work because your subselect is returning more than one value. Of course you can use EXISTS instead of LIKE but that would only return MATCHING values rather than SIMILAR ones. I suggest you make a cursor for this one. It should do the trick.Hope this helps.Good Luck!Crespo.
Arnold Fribble
Yak-finder General
1961 Posts
Posted - 2002-08-06 : 05:58:09
If you want a row for each pattern matched in #myTempTable then use a join:
SELECT A.*, B.wordFROM myTable AS AINNER JOIN #myTempTable AS B ON A.myWord LIKE B.word
If you want each row in myTable that matches something in #myTempTable use a subquery:
SELECT *FROM myTable AS AWHERE EXISTS ( SELECT * FROM #myTempTable AS B WHERE A.myWord LIKE B.word )