all groups > sql server programming > may 2006 >
You're in the

sql server programming

group:

Getting T-SQL to use LIKE, REPLACE, and IN... all at the same time???????????????????


Getting T-SQL to use LIKE, REPLACE, and IN... all at the same time??????????????????? \
5/20/2006 8:33:33 PM
sql server programming:

How in the world would you do this?

The user enters a word like: "BROWN".

The database contains a VarChar() field like: "RED,GREE*,BR*N,BLU*"

A match is found because the 3rd word "BR*N" matches "BROWN".

I guess I would have to use some combination of:
LIKE (for the wildcards)....
REPLACE (to replace the user-friendly *, with the T-SQL % character)....
IN (to match a list of values like RED,GREEN,BROWN,BLUE, etc)
Also... the wildcard characters are in the database... NOT passed from
the user.

But I can't seem to get them all working at the same time.

Help!

(I'm working with MS SQL 2000, asp.net, vb.net... and wanted to use a
parameterized query.)


Re: Getting T-SQL to use LIKE, REPLACE, and IN... all at the same time??????????????????? Uri Dimant
5/21/2006 12:00:00 AM
Hi
What is happening if you have 'BRO'? Should it also be mapped to the search
criterie?

In my opinion ,your best choice is to enable FULL-TEXT-SEARCH engine






[quoted text, click to view]

Re: Getting T-SQL to use LIKE, REPLACE, and IN... all at the same time??????????????????? Hugo Kornelis
5/21/2006 12:00:00 AM
[quoted text, click to view]

Hi A_Michigan_User,

Erland has some techniques on his site to convert a comma-seperated
string to a table with one value per row. See this article:
http://www.sommarskog.se/arrays-in-sql.html

With that table, the rest is a lot easier to accomplish:

SELECT ??? -- Enumerate columns here
FROM TableWithSplitStrings AS t
-- JOIN other tables ???
WHERE 'Brown' LIKE REPLACE(t.TheColumn, '*', '%')

(Untested - if you prefer a tested reply, see www.aspfaq.com/5006)

--
AddThis Social Bookmark Button