Another Way Of Doing This Is To Create A Generic Function That Puts The Values In A Table and Sum The Resulting Table.
i.e. SELECT SUM(*) FROM dbo.ParseByComma('1,2,3,4,5,6,7,8')
/************************************************** ***************
**** Parse A Comma Delimited String Into A Table
************************************************** ***************/
CREATE FUNCTION dbo.ParseByComma (
@String VARCHAR(600) )
RETURNS @TblSubString TABLE
(
VarSubString VARCHAR(10)
)
AS
BEGIN
DECLARE @intPos INT,
@SubStr VARCHAR(10)
-- Remove All Spaces
SET @String = REPLACE(@String, ' ','')
-- Find The First Comma
SET @IntPos = CHARINDEX(',', @String)
-- Loop Until There Is Nothing Left Of @String
WHILE @IntPos > 0
BEGIN
-- Extract The String
SET @SubStr = SUBSTRING(@String, 0, @IntPos)
-- Insert The String Into The Table
INSERT INTO @TblSubString (VarSubString) VALUES (@SubStr)
-- Remove The String & Comma Separator From The Original
SET @String = REPLACE(@String, @SubStr + ',', '')
-- Get The New Index To The String
SET @IntPos = CHARINDEX(',', @String)
END
-- Return The Last One
INSERT INTO @TblSubString (VarSubString) VALUES (@String)
RETURN
END