If value contains these letters, then

Viewed 47210

In SQL Server, is there a way to search (and format) a result for a certain string (like preg_match in PHP):

SELECT (IF (col1 contains 'http'){'<a>' + col 1 + '</a>'}
else {'<b>' + col1 + '</b>'}),
col2
FROM Table

... etc.

Is this possible? I want to format the results based on their content.

3 Answers

I use something like the following:

IF (my_column_name LIKE "%MATCHSTRING%", 1, 0) AS new_column_name,

Leave off the % if you are doing a exact match as opposed to a contains

Related