Is there a method to use contain rather than equal in case statement?
For example, I am checking a database table has an entry
lactulose, Lasix (furosemide), oxazepam, propranolol, rabeprazole, sertraline,
Can I use
CASE When dbo.Table.Column = 'lactulose' Then 'BP Medication' ELSE '' END AS 'BP Medication'
This did not work.
The leading
', 'and trailing','are added so that you can handle the match regardless of where it is in the string (first entry, last entry, or anywhere in between).That said, why are you storing data you want to search on as a comma-separated string? This violates all kinds of forms and best practices. You should consider normalizing your schema.
In addition: don’t use
'single quotes'as identifier delimiters; this syntax is deprecated. Use[square brackets](preferred) or"double quotes"if you must. See “string literals as column aliases” here: http://msdn.microsoft.com/en-us/library/bb510662%28SQL.100%29.aspxEDIT If you have multiple values, you can do this (you can’t short-hand this with the other
CASEsyntax variant or by using something likeIN()):If you have more values, it might be worthwhile to use a split function, e.g.
Results: