14,970,304 members
See more:
i wanted to find the monthly sales by just select the month and year.

below is the sample of i find the sales for Jan and Feb of 2014.
SQL
```SELECT SUM(totalSell) AS monthlyTotal, monthGrp FROM(
SELECT sellDate, SUM(total) as totalSell, Format(sellDate, "yyyy-mm") AS monthGrp FROM(
SELECT sellDate, total FROM sell)
WHERE sellDate BETWEEN Format(#01/2014#, 'mm/yyyy') AND Format(#02/2014#,'mm/yyyy')
GROUP BY sellDate)
GROUP BY monthGrp ORDER BY monthGrp```

but the query above only return the complete sales for Jan and sales on 1 Feb 2014.

eg.
```monthlyTotal     monthGrp
100000         2014-01      <-- complete Jan 2014 Sales (correct)
100          2014-02      <-- Sales on 1st Feb 2014 only (wrong)```
Posted

## Solution 2

SQL
`select *From Table  where month(selldate) between 1 and 2 and year(selldate)=2014`

## Solution 1

you can create your query with the help of following query...
SQL
```DECLARE @Month int
DECLARE @Year int

set @Month = 2
set @Year = 2014

## Solution 3

```<pre lang="SQL">
select sum(total) AS monthlyTotal,
trunc(sellDate)as monthGrp
from sell
where to_char(sellDate,'MM') between 1 and 2
and to_char(sellDate,'YYYY')=2014
group by trunc(sellDate);```

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

Top Experts
Last 24hrsThis month
 OriginalGriff 70 Simon_Whale 50 Dave Kreskowiak 45 Chris Copeland 30 Alexander Sanchez 2021 25
 OriginalGriff 3,885 Richard MacCutchan 2,038 Richard Deeming 1,733 Patrice T 810 Dave Kreskowiak 698

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