Tuesday, March 27, 2012

cursor or query

> Dear all,
> i had a table named saletable i had fields like
> itemgroupid,itemgroupname,saleqty,saleam
ount and saledate.
> i want to sum the saleqty and saleamount by every month and year.by every itemgoup
name
suppose that every year has january month and 31 days in january so i want
that for every year and every month i should sum the qty and sale amount for
Y/M but by Itemgroupname
do not want to give criteria
> for eaxmple
> itemgroupid itemgroupname saleqty saleamount date
> ----
--
> 23101102 HERO LINER 10.00 50467.29 2004-01
-07
> 23101102 HERO LINER 20.00 10924.58 2005-01
-07
> 23101102 HERO LINER 10.00 50467.29 2004-02
-07
> 23101102 HERO LINER 20.00 10924.58 2005-02
-07
> 23101102 HERO LINER 10.00 50467.29 2004-01
-07
> 23101102 HERO LINER 20.00 10924.58 2005-01
-07
> 23204101 Trading Mudgard 10.00 6000.00 2005-04-21
> 23204101 Trading Mudgard 10.00 50467.29 2004-01-07
> 23204101 Trading Mudgard 20.00 10924.58 2005-01-07
> 23204101 Trading Mudgard 20.00 10924.58 2005-02-07
> 23204101 Trading Mudgard 10.00 50467.29 2004-01-07
> 23204101 Trading Mudgard 20.00 10924.58 2005-01-07
> I WANT like this
> for every month and year
> 23204101 Trading Mudgard 20.00 100934.58 2004-01
> 23204101 Trading Mudgard 60.00 2326000.00 2005-01
> 23204101 Trading Mudgard 10.00 6000.00 2005-07
> thanx
--
waiting for solution
from
SufianSELECT itemgroupid, itemgroupname, MIN(date),
SUM(saleqty), SUM(saleamount)
FROM SaleTable
GROUP BY YEAR(date), MONTH(date)
If that's not what you want then please post DDL, sample data, required
results. See:
http://www.aspfaq.com/etiquette.asp?id=5006
David Portas
SQL Server MVP
--|||Thanx David it worked and once again thanx
--
waiting for solution
from
Sufian
"David Portas" wrote:

> SELECT itemgroupid, itemgroupname, MIN(date),
> SUM(saleqty), SUM(saleamount)
> FROM SaleTable
> GROUP BY YEAR(date), MONTH(date)
> If that's not what you want then please post DDL, sample data, required
> results. See:
> http://www.aspfaq.com/etiquette.asp?id=5006
> --
> David Portas
> SQL Server MVP
> --
>
>

No comments:

Post a Comment