SQL to find upper case words from a column

后端 未结 7 1428
南笙
南笙 2020-12-10 02:56

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

相关标签:
7条回答
  • 2020-12-10 03:34

    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.

    0 讨论(0)
提交回复
热议问题