Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:41:03+00:00 2026-06-04T01:41:03+00:00

Is there a method to use contain rather than equal in case statement? For

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:41:05+00:00Added an answer on June 4, 2026 at 1:41 am
    CASE WHEN ', ' + dbo.Table.Column +',' LIKE '%, lactulose,%' 
      THEN 'BP Medication' ELSE '' END AS [BP Medication]
    

    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.aspx

    EDIT If you have multiple values, you can do this (you can’t short-hand this with the other CASE syntax variant or by using something like IN()):

    CASE 
      WHEN ', ' + dbo.Table.Column +',' LIKE '%, lactulose,%' 
      WHEN ', ' + dbo.Table.Column +',' LIKE '%, amlodipine,%' 
      THEN 'BP Medication' ELSE '' END AS [BP Medication]
    

    If you have more values, it might be worthwhile to use a split function, e.g.

    USE tempdb;
    GO
    
    CREATE FUNCTION dbo.SplitStrings(@List NVARCHAR(MAX))
    RETURNS TABLE
    AS
       RETURN ( SELECT DISTINCT Item FROM
           ( SELECT Item = x.i.value('(./text())[1]', 'nvarchar(max)')
             FROM ( SELECT [XML] = CONVERT(XML, '<i>'
             + REPLACE(@List,',', '</i><i>') + '</i>').query('.')
               ) AS a CROSS APPLY [XML].nodes('i') AS x(i) ) AS y
           WHERE Item IS NOT NULL
       );
    GO
    
    CREATE TABLE dbo.[Table](ID INT, [Column] VARCHAR(255));
    GO
    
    INSERT dbo.[Table] VALUES
    (1,'lactulose, Lasix (furosemide), oxazepam, propranolol, rabeprazole, sertraline,'),
    (2,'lactulite, Lasix (furosemide), lactulose, propranolol, rabeprazole, sertraline,'),
    (3,'lactulite, Lasix (furosemide), oxazepam, propranolol, rabeprazole, sertraline,'),
    (4,'lactulite, Lasix (furosemide), lactulose, amlodipine, rabeprazole, sertraline,');
    
    SELECT t.ID
      FROM dbo.[Table] AS t
      INNER JOIN dbo.SplitStrings('lactulose,amlodipine') AS s
      ON ', ' + t.[Column] + ',' LIKE '%, ' + s.Item + ',%'
      GROUP BY t.ID;
    GO
    

    Results:

    ID
    ----
    1
    2
    4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any method to use bubbles programmatically for give suggestions in UITextfield.
What encryption method does the .NET FormsAuthentication.Encrypt() method use? There's no mention in the
Is there a standard method I can use in place of this custom method?
Is there a way to use ArrayList() method to add strings to an array
I know in jQuery 1.4.x there is a method delay(). We can use it
Is there a way to use the CompiledQuery.Compile method to compile the Expression associated
Using ASP.Net MVC 2, is there any way to use the RedirectToAction() method of
I want to use the <operation>Asnyc methods rather than the Begin<operation>/End<operation> on my WCF
As per my knowledge, there are 3 methods to compile and use C code
Trying to use GridBagLayout. I have the method called buildLabel. This creates three label.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.