all groups > sql server new users > november 2006 >
You're in the

sql server new users

group:

count number of items in string comma delimited


Re: count number of items in string comma delimited Arnie Rowland
11/10/2006 1:01:54 PM
sql server new users:
The articles below will help you understand what you can and can't do with a
comma delimited string simulating an array.

Arrays and Lists in SQL Server
http://www.sommarskog.se/arrays-in-sql.html
http://www.realsqlguy.com/?p=9
http://www.aspfaq.com/2248

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]

count number of items in string comma delimited Alejandro
11/10/2006 3:49:04 PM
Is it possible to count the number of items from a comma delimited string ?

I select * from table where id IN (parameter)

the parameter is: 18,23,324,34

That is four items, is it possible to count how many items are in the string
? so that the results in the case above results would be : 4 ?

A

Re: count number of items in string comma delimited Hilary Cotter
11/10/2006 7:30:18 PM
here is the way I do it

declare @string varchar(20)
set @string='18,23,324,34'
declare @numberOfCommas int
select @numberOfCommas=len(@string)-len(replace(@string,',',''))
print @numberOfCommas



--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.

This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com



[quoted text, click to view]

Re: count number of items in string comma delimited Otis Mukinfus
11/11/2006 8:26:39 PM
[quoted text, click to view]

string[] s = parameters.Split(new char[] {','});
int num = s.length;

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
AddThis Social Bookmark Button