• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Select single value from csv string

Hello,

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!
0
austerhaus
Asked:
austerhaus
  • 2
  • 2
1 Solution
 
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

0
 
HoggZillaCommented:
Does the value have to be in the specific column, I assume it does.
0
 
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.
0
 
HoggZillaCommented:
I think angel got this one, check that out. I am adding that one to my knowledgebase.
0
 
austerhausAuthor Commented:
Yep, worked great. Thanks for the fast reply!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now