Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have an problem that,

I have an table that consist of Amount(decimal),MonthId(Int),Year(int)

and I want to reterive an sum of amount between 4(Month),2013(Year) to 3(Month),2014(Year) through query.


Please,any one can suggest me how to do this..
Posted
Comments
Ajith K Gatty 6-May-14 1:39am    
Hi Ajay,

try solution 1 and 2.
If you have date a column you can easily implement BETWEEN Operator.
Ex: SELECT * FROM Orders
WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#

Good Luck.

Try
select * from table where (Year >= 2013 and Month >=4) AND (Year <= 2014 and Month <=3)
 
Share this answer
 
v2
Comments
ajays3356 6-May-14 0:49am    
i have try this,it gives null,But i have columns in table

But i want all the column Between 4,2013 and 3,2013
Laiju k 6-May-14 1:01am    
please check whether you have mentioned the database or not
ajays3356 6-May-14 1:11am    
I have mention the database.
Hi,

Try following solution :

SQL
select SUM(amt) from
(
sELECT SUM(amount) amt FROM test1 WHERE ([month]>=3 and [year]=2013)
union
select sum(amount) amt from test1 where ([month]<=3 and [year]=2014)
) test


Change your year and month accordingly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900