How to format a string field into number format in a select statement?

Database
Enthusiast

How to format a string field into number format in a select statement?

 

Hi, I have a field called "Cases". it's formatted as string. I want to convert it into number  into a select statement and sum it up. i tried  this but didn't work:

 

select SUM (Cast(Cases) as integer).

 

any help is appreciated


Accepted Solutions
Highlighted
Teradata Employee

Re: How to format a string field into number format in a select statement?

If the field has only a string of digits, optionally a leading or trailing + or -, and optionally leading and/or trailing spaces, then just fixing the placement of parentheses should work.

SUM(CAST(Cases AS INTEGER))

Otherwise give some examples of data causing trouble.

1 ACCEPTED SOLUTION
1 REPLY
Highlighted
Teradata Employee

Re: How to format a string field into number format in a select statement?

If the field has only a string of digits, optionally a leading or trailing + or -, and optionally leading and/or trailing spaces, then just fixing the placement of parentheses should work.

SUM(CAST(Cases AS INTEGER))

Otherwise give some examples of data causing trouble.