It does not print the 'C' element of the list because the C is not followed by a comma, and after processing the B element, the while loop ends because it does not find another comma.
There are 2 simple solutions
1) As shown below : after the end of the while loop, print any remaining text
2) Add another 'dummy' comma separator at the end of the string before processing. This will ensure that the last element is processed by the code in the loop
DECLARE @pos INT
DECLARE @len INT
DECLARE @value nvarchar(4000)
set @pos = 0
set @len = 0
WHILE CHARINDEX(',', @valueList, @pos+1)>0
BEGIN
set @len = CHARINDEX(',', @valueList, @pos+1) - @pos
set @value = SUBSTRING(@valueList, @pos, @len)
print @value
set @pos = CHARINDEX(',', @valueList, @pos+@len) +1
END
print SUBSTRING(@valueList, @pos, @len)
Hope this helps
Ali.