Solved

How to sum the quantity or price on SQL Table SUM ()

Posted on 2013-01-16
2
631 Views
Last Modified: 2013-01-16
Our Drug Table has only 3 columns like GenericCode, DrugName, Qty.

SUM(QTY) is the Column which i expect to be along with my Select Query


GenericCode       DrugName         Qty           SUM(Qty)
102010                 ABC                  10                   40
102010                 ABC                  20                    40
102010                 ABC                  10                    40

102111                 EFG                  10                     20
102111                 EFG                  10                     20
0
Comment
Question by:chokka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 38783895
use this

select *, sum(qty) over (partition by GenericCode) from yourtable

More details:

http://msdn.microsoft.com/en-us/library/ms189461(v=sql.100).aspx
0
 
LVL 43

Expert Comment

by:zephyr_hex (Megan)
ID: 38783909
select DrugName,sum(Qty) from DrugTable group by DrugName

i'm not clear from your data set whether you also want to group by GenericCode.  if that's the case, then
select GenericCode,DrugName,sum(Qty) from DrugTable group by GenericCode,DrugName
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question