SQL - Converting from VARCHAR to Decimal

~J~

~J~

Soldato
Joined
20 Oct 2003
Posts
7,558
Location
London
I've got a table which has a field that can hold a multitude of values.

What I want to do is SUM up the field, if it can't convert the text, then it ignores it and/or gives it a zero.

I get an error which reads "Error converting varchar to numeric"

Anyone know how I can SUM up the column, ignoring any errors it finds along the way?

TIA
 
Soldato
Joined
25 Feb 2003
Posts
2,713
Location
Deep dark hole
something like
Code:
CASE WHEN [Field] LIKE '[0-9]+' THEN [Field] ELSE 0 END
as MSSQL does auto convert to numeric if required
totally untested, but the sort of thing I would probably do :)
 
Back
Top Bottom