Extract Cumulative data and daily data from same Stored PRocedure

Hello Experts,
I have a table called Tb_1 that looks like this:
Wt     Date
1.5      1/20/2014
2.3      1/20/2014
6.2      1/21/2014
3.8      1/22/2014

I would like to filter the stored procedure like this:
Select SUM(Wt) From Tb_1
Where Date Between ‘1/20/2014’ And  ‘1/21/2014’
[Output = 10.0]

Select SUM(Wt) From Tb_1
Where = ‘1/21/2014’
[Output = 6.2]

The First filter returns the total Wt of 10.0 between 1/20/2014 and 1/21/2014.
The Second filter returns total Wt of 6.21 for 1/21/2014 only.

Of course this is easy to do by writing two separate stored procedures but I would like to get both results for SUM(Wt) of 10.0 and 6.2 (in this example) from the same stored procedure.

Does anyone know how to do this?

Thanks!
SaxitalisAsked:
Who is Participating?
 
HuaMin ChenSystem AnalystCommented:
Try to put this

select (Select SUM(Wt) From Tb_1
Where Date Between ‘1/20/2014’ And  ‘1/21/2014’) sum1,
(Select SUM(Wt) From Tb_1
Where = ‘1/21/2014’) sum2

Open in new window

within your SP
0
 
Olaf DoschkeSoftware DeveloperCommented:
Simply parameterize your SP and then do the query

Select SUM(Wt) From Tb_1
Where Date Between @MinDate And  @MaxDate

If you want data from a single day simply call it with min date = max date.

Details about parameters needed? http://technet.microsoft.com/en-US/library/ms187926(v=SQL.105).aspx

Bye, Olaf.
0
 
SaxitalisAuthor Commented:
This works great - Thank you sir!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.