0

i have the following T-SQL statement:

select top 10 value1 from table1 where condition1 = 12345

result:

5449.0              
228231.0            
0.0                 
3128.0              
6560.0              
4541.0              
2119.0              
0.0                 
0.0                 
4183.0              

the data type of value1 = "[char] (20) COLLATE Latin1_General_CS_AS NULL"

please note, each result line has 20 chars i.e. "5449.0______________" filled up with spaces.

I want to sum all this columns. how can i convert these values to a summable data type?

1

1 Answer 1

0

Use cast or convert:

-- for demo
declare  @v char(20)
set @v = '228231.9            '
-- real magic
select cast(@v as real)

So this is the select in your case:

select cast(value1 as real) from table1 where condition1 = 12345
select sum(cast(value1 as real)) from table1 where condition1 = 12345
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.