views:

25

answers:

4

Greetings,

I'm looking for a SQL Server statement to retrieve records Where myfield content giving sub-string.

Thank you,

A: 

You can use CharIndex

Select * From YourTable
Where
CharIndex('yoursubstring', myfield) > 0
RandomNoob
A: 

Try PatIndex.

SELECT *
FROM Table
WHERE patindex('%string%', data ) > 0
Simmo
A: 
select * from mytable where myfield like '%literalstring%'

or

select * from mytable where myfield like '%' + @stringvar + '%'

...not really clear on whether your substring is a literal or a variable

kekekela
+1  A: 

Another possibility is to use LIKE:

SELECT
    MT.column_1,
    ....
FROM
    My_Table MT
WHERE
    some_column LIKE '%' + @search_string + '%'
Tom H.
This will work, but using the `%search%` pattern is a sure-fire way to skip any indices that might be present, thus resulting in a full table scan and thus horribly bad performance....
marc_s
That's going to be the case in any solution, short of full text searches, where you're trying to find a string within a column.
Tom H.