error in using cases with sql query any

advertisements

I want to use like in case statement and search string from a particular colmun if any part of that string contains 'Moderate to severe aortic stenosis' THEN instead of full string I want to display 'Moderate to Severe' if any part of that string contains 'Severe aortic stenosis with' THEN instead of full string I want to display 'Severe' if that string contains 'moderate aortic stenosis present' THEN instead of full string I want to display 'Moderate'

Below is my query not working some systax error

SELECT (CASE  a.Column when  LIKE '%Moderate to severe aortic stenosis%' THEN 'Moderate to Severe'
            when  LIKE '%Severe aortic stenosis with%' THEN 'Severe'
            when  LIKE '%moderate aortic stenosis present%' THEN 'Moderate' else ' ' end)
       from MyTable a

Please help


There are syntax errors in your query:

SELECT
  CASE
     WHEN a.Column LIKE '%Moderate to severe aortic stenosis%' THEN 'Moderate to Severe'
     WHEN a.Column LIKE '%Severe aortic stenosis with%' THEN 'Severe'
     WHEN a.Column LIKE '%moderate aortic stenosis present%' THEN 'Moderate' else ' '
  END
FROM
 MyTable a

Field a.Column should appear after every WHEN in comparison with LIKE.