﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Chad Casady  / List Count / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 10:09:45 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: List Count</title><link>http://www.sqlservercentral.com/Forums/Topic1073758-2913-1.aspx</link><description>declare @mylist nvarchar(100), @delimiter VARCHAR(2)set @mylist = 'A,B, C, D , 1, 2,345, EFG, H, 'set @delimiter = ','select	@mylist list,		(LEN(@mylist) - LEN(replace(@mylist,@delimiter,'')))/LEN(@delimiter)		+		case when right(rtrim(LTRIM(@mylist)),1) = @delimiter then 0 else 1 end itemcount</description><pubDate>Thu, 14 Jul 2011 04:51:29 GMT</pubDate><dc:creator>suryakant_ker</dc:creator></item><item><title>RE: List Count</title><link>http://www.sqlservercentral.com/Forums/Topic1073758-2913-1.aspx</link><description>[code="sql"]DECLARE @Numbertable table(	ID INT PRIMARY KEY	)INSERT INTO @Numbertableselect TOP 1000 ROW_NUMBER() OVER(order by si.object_id)from sys.objects si,sys.objects sdeclare @mylist nvarchar(100)set @mylist = 'A,B, C, D , 1, 2,345, EFG, H,'select COUNT(string)from(select 	NULLIF(SUBSTRING(@mylist,id,CHARINDEX(',',@mylist+',',id)-ID),'') AS stringfrom @Numbertablewhere id &amp;lt;= LEN(@mylist) and SUBSTRING(','+@mylist,ID,1) = ',')d[/code]</description><pubDate>Wed, 27 Apr 2011 04:10:33 GMT</pubDate><dc:creator>Mitesh Oswal</dc:creator></item><item><title>RE: List Count</title><link>http://www.sqlservercentral.com/Forums/Topic1073758-2913-1.aspx</link><description>You're exactly right.  I was lost in a solution that considered delimiters within text qualifiers and ended up with something far more complex than was necessary.</description><pubDate>Mon, 07 Mar 2011 08:59:51 GMT</pubDate><dc:creator>Chad Casady</dc:creator></item><item><title>RE: List Count</title><link>http://www.sqlservercentral.com/Forums/Topic1073758-2913-1.aspx</link><description>@paul_ramster - My thoughts exactly.  That is the way I've always done it in SQL and other languages.  The only reason you'd need to use a loop to get a count in a list like this is if you had a text qualifier, where when the delimiter falls within the text qualifier, it is not a delimiter.</description><pubDate>Mon, 07 Mar 2011 06:53:33 GMT</pubDate><dc:creator>jmpatchak</dc:creator></item><item><title>RE: List Count</title><link>http://www.sqlservercentral.com/Forums/Topic1073758-2913-1.aspx</link><description>This is simpler...[code="sql"]declare @mylist nvarchar(100);set @mylist = 'A,B, C, D , 1, 2,345, EFG, H,';declare @delim varchar(2)=',';select LEN(@mylist) - LEN(replace(@mylist,@delim,''));[/code]</description><pubDate>Mon, 07 Mar 2011 02:04:32 GMT</pubDate><dc:creator>paul_ramster</dc:creator></item><item><title>RE: List Count</title><link>http://www.sqlservercentral.com/Forums/Topic1073758-2913-1.aspx</link><description>Use a tally table surely?</description><pubDate>Mon, 07 Mar 2011 01:26:05 GMT</pubDate><dc:creator>julian.fletcher</dc:creator></item><item><title>List Count</title><link>http://www.sqlservercentral.com/Forums/Topic1073758-2913-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/UDF/72560/"&gt;List Count&lt;/A&gt;[/B]</description><pubDate>Sat, 05 Mar 2011 12:34:49 GMT</pubDate><dc:creator>Chad Casady</dc:creator></item></channel></rss>