What about something like

CREATE FUNCTION dbo.f_ReturnSum (@inputVal varchar(12))

RETURNS INT

AS

BEGIN

declare @i TINYINT

declare @returnedVal int

SET @i = 1

SET @returnedVal = 0

WHILE @i <= LEN(@inputVal)

Begin

set @returnedVal = @ReturnedVal + CAST(SUBSTRING(@inputval,@i,1) as

tinyint)

set @i = @i + 1

End

RETURN @returnedVal

END

GO

select dbo.f_ReturnSum('125111111111')

--

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)

www.SQLDTS.com - The site for all your DTS needs.

I support PASS - the definitive, global community

for SQL Server professionals -

http://www.sqlpass.org
"Chris Michael" <ne**@intomobiles.com> wrote in message

news:c6************@ID-211081.news.uni-berlin.de...

I've got a string of numbers, say 123456 (the actually number is 12 digits

long). I need to calculate the sum of each individual number in the string

of numbers, so in the example of 123456 the sum would be 21 (1+2+3+4+5+6).

Thanks