Select single value from csv string


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!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
like this:
declare @b int
select @b = count(*) from dbo.ParmsToList(@your_csv_string, ',') l where l.Value = 'moe'

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve HoggITCommented:
Does the value have to be in the specific column, I assume it does.
austerhausAuthor Commented:
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.
Steve HoggITCommented:
I think angel got this one, check that out. I am adding that one to my knowledgebase.
austerhausAuthor Commented:
Yep, worked great. Thanks for the fast reply!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.