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.
| Author |
Topic |
|
gomo
Starting Member
4 Posts |
Posted - 2011-07-21 : 14:32:37
|
| Hi,I want to sum a number of colums but also show distinct parts, i.e.currently:Part no qty net value123 1 10456 5 80123 10 60so i would like to achievePart no qty net value123 11 70456 5 80thanks for your helpmo |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-07-21 : 15:34:41
|
Use the SUM function, and group by the Part no.select PartNo, SUM(Qty), SUM(NetValue) from PartsTable group by PartNo |
 |
|
|
gomo
Starting Member
4 Posts |
Posted - 2011-07-21 : 15:49:59
|
quote: Originally posted by sunitabeck Use the SUM function, and group by the Part no.select PartNo, SUM(Qty), SUM(NetValue) from PartsTable group by PartNo
This is the query that i have at the moment but it still lists the parts separately.select spart, sum(soq) as qty,sum(sprice)as netfrom salesitemsinner join salesorderson salesitems.sn = salesorders.sonwhere salesorders.scustomer = 'abc' and salesitems.sduedate between '2010-04-01 00:00:00.000' and '2011-03-31 00:00:00.000'group by spart |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-07-21 : 15:54:31
|
| The query you posted would list one and only one row for each spart. Is that not what you are looking for? Can you post sample data that you are getting and a sample of what you want to get? |
 |
|
|
gomo
Starting Member
4 Posts |
Posted - 2011-07-21 : 15:59:38
|
quote: Originally posted by sunitabeck The query you posted would list one and only one row for each spart. Is that not what you are looking for? Can you post sample data that you are getting and a sample of what you want to get?
What i am trying to get to is how many parts have been sold with net value between dates. So i want one part no with total qty and total net value.My current query shows the same part many times, as well as the qty and net value.thanks |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-07-21 : 17:46:53
|
quote: Originally posted by gomo [quote]My current query shows the same part many times, as well as the qty and net value.thanks
Then can you show us the real query you are using? Because the one you listed above is not it. |
 |
|
|
|
|
|
|
|