Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to get sum of column values between two dates?

Author  Topic 

Akshaya Pargunan
Starting Member

10 Posts

Posted - 2011-10-10 : 08:19:48
I have table like below
Monday Tuesday Wednesday Thursday Friday Saturday Sunday WeekEndDate
------ ------- --------- -------- ------ -------- ------ -----------
2 3 2 5 5 8 0 02/10/2011
0 3 7 1 0 2 4 09/10/2011
3 0 2 0 5 0 6 16/10/2011
2 3 0 1 0 8 9 23/10/2011
1 6 2 4 0 3 0 30/10/2011

Weekenddate has sunday's date,the row has one week date from monday to sunday.
I have two inputs
fromdate = 06/10/201
todate = 20/10/2011

how can return sum(monday),sum(tusday),sum(wednesday),sum(thursday),sum(friday),sum(saturday),sum(sunday) with in these two dates from the table above?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-10-10 : 08:41:12
triplicate
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=166463

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-10 : 08:41:30
use a expression based on DATEPART(dw,GETDATE()) like

SUM(CASE WHEN DATEPART(dw,GETDATE()) =1 THEN Yourfield else 0 end),SUM(CASE WHEN DATEPART(dw,GETDATE()) =2 THEN Yourfield else 0 end),...

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-10-10 : 08:47:54
I gave an answer to this post in the referenced post above giving a couple of suggestions depending on what the requirement really is - seems to have been deleted. I hope the OP has a copy of that solution and can post it wherever he wants to continue the thread as I'm not going to repost it.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Akshaya Pargunan
Starting Member

10 Posts

Posted - 2011-10-10 : 09:03:42
its saying i dont have access to this post
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-10-10 : 09:50:01
Didn't you delete it? It sems to have gone. Otherwise it sounds like a forum bug.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -