I have a description column in my table and its values are:
This is a EXAMPLE
This is a TEST
This is a VALUE
I want to display only EXAMPLE
If you only need to "display" the result without changing the values in the column then you can use CASE WHEN
(in the example Description
is the column name):
Select CASE WHEN Description like '%EXAMPLE%' then 'EXAMPLE' WHEN Description like '%TEST%' then 'TEST' WHEN Description like '%VALUE%' then 'VALUE' END From [yourTable]
The conditions are not case sensitive even if you write it all in uppercase.
You can add Else '<Value if all conditions are wrong>'
before the END
in case there are descriptions that don't contain any of the values. The example will return NULL for those cases, and writing ELSE Description
will return the original value of that row.
It also works if you need to update. It is simple and practical, easy way out, haha.