Select single value from csv string

Posted on 2008-11-17
Last Modified: 2012-05-05

I am using SQL Server 2000.I have a stored procedure that accepts (among other things) a varchar csv string, values that come from an asp multi-select list. In the sproc, i need to set a variable if that csv string contains a specific value. I have a tally table to parse the csv into individual rows but I am yet unable to get it to work

As an example: let's say that the csv string = 'homer, bart, moe, milhouse, apu'
I need logic that will set a var (bit) to true if the csv string contains 'moe' and false if it does not.

Please let me know if additional information is required. Thank you in advance!
Question by:austerhaus
    LVL 142

    Accepted Solution

    like this:
    declare @b int
    select @b = count(*) from dbo.ParmsToList(@your_csv_string, ',') l where l.Value = 'moe'

    Open in new window

    LVL 17

    Expert Comment

    Does the value have to be in the specific column, I assume it does.
    LVL 1

    Author Comment

    The value I am looking for will not necessarily be in the string. If it is then my var (i.e. @varMoeExists) should be set to true otherwise, it will need to be false.
    LVL 17

    Expert Comment

    I think angel got this one, check that out. I am adding that one to my knowledgebase.
    LVL 1

    Author Closing Comment

    Yep, worked great. Thanks for the fast reply!

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
    I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now