Fastest way to calculate summary of database field

Posted by Jo-wen on Stack Overflow See other posts from Stack Overflow or by Jo-wen
Published on 2010-05-31T11:58:33Z Indexed on 2010/05/31 12:02 UTC
Read the original article Hit count: 302

Filed under:

I have a ms-sql table with the following structure:

Name nvarchar; Sign nvarchar; Value int

example contents:
Test1, 'plus', 5
Test1, 'minus', 3
Test2, 'minus', 1

I would like to have totals per "Name". (add when sign = plus, subtract when sign = minus)

result:
Test1, 2
Test2, -1

I want to show these results (and update them when a new record is added)... and I'm looking for the fastest solution! [sproc? fast-forward cursor? calculate in .net?]

© Stack Overflow or respective owner

Related posts about sql-server