troubleshooting Question

Running Totals Condition Check in SQL

Avatar of ASPDEV
ASPDEV asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008SQL
10 Comments1 Solution400 ViewsLast Modified:
Hello Experts,

I need like this

AMT  COMM DATETIME
100    1         09/01/2010
110    10      09/02/2010
160   50      09/03/2010
170   10      09/04/2010

Running totals works fine with this query:
select (select SUM(isnull(AMT,0)+ISNULL(COMM,0)) from #yourtable t1 where t1.dtColumn <= t2.dtColumn) AMT,COMM,dtColumn
  from #yourtable t2

If I run this query again and again I get Larger values in the AMT field, since its update with another set.

Condition:
If COMM is not changed then NO UPDATE.
IF COMM is changed then UPDATE to have running  totals.

I need to check whether COMM column is changed or not, if not then I need Updated statement.But Finally it should be Running Total.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros