Learn how to a build a cloud-first strategyRegister Now


Select single value from csv string

Posted on 2008-11-17
Medium Priority
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
  • 2
  • 2
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 22979635
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

ID: 22979642
Does the value have to be in the specific column, I assume it does.

Author Comment

ID: 22979700
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

ID: 22979756
I think angel got this one, check that out. I am adding that one to my knowledgebase.

Author Closing Comment

ID: 31517613
Yep, worked great. Thanks for the fast reply!

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

810 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