SQL Server: Sum values from multiple rows into one row -


i trying sum values multiple rows. example:

my output is:

id  value --------- 1    3 1    4 

what see is:

id  value --------- 1   7 

this code:

select     id case sum(cast(value float))     when 0 [other_value]     else isnull([value] ,'')     end  'value' table1 id = 1 group id 

i saw solutions online such had include group by in order avoid error:

is invalid in select list because not contained in either aggregate function or group clause

but, still no sum.

note: values varchar, therefore, need cast

you trying sum string (even if cast it) query work if isnull goes 0 or numeric value

select id, sum(case when cast(value float) = 0 cast([other_value] float) else isnull([value], 0)  end) 'value' table1 id = 1 group id 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -